Free · No sign-up needed

Stop memorising solutions. Learn the 53 patterns behind them.

Every LeetCode problem is a variation of a few core patterns. Work through them in order, learn the signal that tells you which one to use, then practise with hints that nudge you instead of giving the answer away.

53patterns
325hand-picked problems
10stages, easy to hard
0spoilers
New to DSA?

How to use this roadmap

Follow it top to bottom. Each stage only uses ideas from the stages before it.

1

Know one language

Loops, if/else, functions and arrays in Java, C++ or Python. That's all you need for Stage 1.

2

Easy first, always

Every pattern lists Easy, then Medium, then Hard. Do 3–4 Easy before touching a Medium.

3

Struggle 30 minutes

Stuck after 30–45 minutes? Take one hint, not the solution. Then try again.

4

One pattern at a time

Read the pattern's guide, solve its problems, then move on. 1–2 problems a day beats 20 on a Sunday.

5

Revisit after a week

Re-solve anything you needed a hint for. That's when the pattern actually sticks.

Which pattern is this problem?

Type a clue from the problem statement, or pick a common one.

Stage 1

Foundations (Start Here)

New to coding? Begin here5 patterns

Use it when

Warm-up: digits of a number, running totals, simple loops and conditions. Do these if you're new to coding or to your language.

Key idea

Break the number or array into steps you can do by hand, then turn each step into a loop. Use n % 10 to get the last digit and n / 10 to drop it.

  1. Fizz BuzzEasy
  2. Running Sum of 1d ArrayEasy
  3. Richest Customer WealthEasy
  4. Number of Steps to Reduce a Number to ZeroEasy
  5. Count the Digits That Divide a NumberEasy
  6. Palindrome NumberEasy
  7. Plus OneEasy
  8. Reverse IntegerMedium
  9. Sum of DigitsEasy
  10. Prime or NotEasy
  11. GCD and LCMEasy
Full guide

Use it when

Reading, updating and rearranging an array in place; tracking a best-so-far value in one pass.

Key idea

Walk the array once with an index, keep a 'write' pointer for in-place edits, and keep running variables (min, max, count) instead of re-scanning.

  1. Find Numbers with Even Number of DigitsEasy
  2. Remove ElementEasy
  3. Remove Duplicates from Sorted ArrayEasy
  4. Merge Sorted ArrayEasy
  5. Check if Array Is Sorted and RotatedEasy
  6. Squares of a Sorted ArrayEasy
  7. Best Time to Buy and Sell StockEasy
  8. Rotate ArrayMedium
  9. Second Largest ElementEasy
  10. Move Zeros to EndEasy
Full guide

Use it when

"Have I seen this before?", counting things, or finding a matching pair fast.

Key idea

A HashMap/HashSet gives O(1) lookups, so one pass with a map replaces a nested loop. Store what you've seen, and check for the complement as you go.

  1. Two SumEasy
  2. Contains DuplicateEasy
  3. Valid AnagramEasy
  4. Ransom NoteEasy
  5. First Unique Character in a StringEasy
  6. Intersection of Two ArraysEasy
  7. Group AnagramsMedium
  8. Longest Consecutive SequenceMedium
  9. Most Frequent ElementEasy
Full guide
Stage 2

Arrays & Strings

7 patterns

Use it when

Contiguous subarray, "longest/shortest/max sum" with a size k or a condition.

Key idea

Grow the right edge, shrink the left edge when the window breaks the rule. Keep a running sum or count instead of recomputing.

  1. Maximum Sum Subarray of Size KEasy
  2. Max Consecutive OnesEasy
  3. Max Consecutive Ones IIIMedium
  4. Subarray Product Less Than KMedium
  5. Fruits Into BasketsMedium
  6. Minimum Size Subarray SumMedium
  7. Sliding Window MaximumHard
  8. Subarray with K Distinct IntegersHard
Full guide
Stage 3

Binary Search

2 patterns

Use it when

Sorted (or rotated sorted) input, find a target or a boundary, O(log n) required.

Key idea

Keep an invariant on [lo, hi] and halve it each step. Decide which half is sorted when rotated.

  1. Binary SearchEasy
  2. Sqrt(x)Easy
  3. Search Insert PositionEasy
  4. Search in Rotated Sorted ArrayMedium
  5. Find Minimum in Rotated Sorted ArrayMedium
  6. Find Peak ElementMedium
  7. Find First and Last Position of ElementMedium
  8. Search a 2D Matrix IIMedium
Full guide

Use it when

"Minimum possible maximum", "least speed/capacity/days so that…".

Key idea

The answer lies in a numeric range and feasibility is monotonic. Binary search the answer and write a greedy check(x).

  1. Koko Eating BananasMedium
  2. Capacity To Ship Packages Within D DaysMedium
  3. Min Speed to Arrive on TimeMedium
  4. Min Days to Make M BouquetsMedium
  5. Magnetic Force Between Two BallsMedium
  6. Split Array Largest SumHard
Full guide
Stage 4

Stacks

6 patterns
Stage 5

Recursion & Linked Lists

6 patterns
Stage 6

Trees

4 patterns

Use it when

Lowest common ancestor, build a tree from traversals, serialize.

Key idea

LCA: the node where p and q split into different subtrees. Construction: the preorder root splits the inorder array.

  1. Invert Binary TreeEasy
  2. Lowest Common Ancestor of Binary TreeMedium
  3. Flatten Binary Tree to Linked ListMedium
  4. Construct Binary Tree from Preorder & InorderMedium
  5. Construct Binary Tree from Inorder & PostorderMedium
  6. Kth Ancestor of a Tree NodeHard
  7. Serialize and Deserialize Binary TreeHard
Full guide
Stage 7

Heaps & Backtracking

5 patterns

Use it when

k largest/smallest/most frequent, k closest, merge k sorted lists.

Key idea

Keep a heap of size k so each push costs O(log k). Use a min-heap for the largest k.

  1. Kth Largest Element in a StreamEasy
  2. Last Stone WeightEasy
  3. Top K Frequent WordsMedium
  4. Kth Largest Element in an ArrayMedium
  5. Find K Pairs with Smallest SumsMedium
  6. Find Median from Data StreamHard
  7. Smallest Range Covering K ListsHard
Full guide
Stage 8

Graphs

5 patterns
Stage 9

Greedy & Dynamic Programming

9 patterns
Stage 10

Tries & Bits

4 patterns

No pattern matches that clue. Try a simpler word like “array”, “tree” or “graph”.

Practise like you have a tutor beside you

The AlgoSolveo extension (free, launching soon) opens next to any LeetCode problem. When you're stuck, it gives the smallest hint that gets you moving again, and your solved problems tick off on this roadmap automatically.

Join the extension waitlist
1Nudge. “The array is sorted. What does that let you do with two indices?”
2Direction. “Start one pointer at each end. Which one moves when the sum is too big?”
3Structure. Pseudocode outline if you still need it.
✓Solved. It's marked on your roadmap and dashboard.