Master coding interview patterns

Clear, step-by-step guides to data structures, algorithms and LeetCode problems, with Python solutions and complexity analysis.

two_sum.py
def two_sum(nums, target):
    seen = {}
    for i, n in enumerate(nums):
        need = target - n
        if need in seen:
            return [seen[need], i]
        seen[n] = i

# One pass, O(n) time, O(n) space

Latest articles

All articles →

A four week study plan

Full roadmap →
  1. Foundations

    Arrays, strings and hash maps. Learn to spot when a lookup table removes a nested loop. Start here.

  2. Core patterns

    Two pointers, sliding window and binary search cover a huge share of easy and medium problems. Binary search.

  3. Trees and graphs

    Recursion, DFS, BFS and backtracking. Practise drawing the call stack before you code. Trees and graphs.

  4. Dynamic programming

    Move from recursion to memoization to tabulation, then do timed mock interviews. Dynamic programming.

How we write our guides

Interview preparation is mostly about understanding, not memorising answers. Each article explains the idea in plain language first, then shows the code.

  • Problem statement and a simple worked example before any code.
  • Brute force first, then the improvement, so you see why it works.
  • Python solutions with time and space complexity stated.
  • Free to read, with no sign-up needed.
  • Found a mistake? Tell us through the contact page and we will correct it.

Built and edited by Nilesh Kumar

I am a second-year BTech student and the person behind LeetPrep. I choose every topic, review and edit each guide before it goes live, and read every message that comes through the contact page. Code examples are tested before they are published.

More about the author →

Have a topic you want covered?

Tell us which problem or concept gave you trouble and we will consider writing a guide on it.

Contact us