Patterns-First 50
Stop solving each problem from scratch. Recognize the pattern in the first thirty seconds and execute the template.
By Alex Chen, Founder, InterviewChamp.AI · 50 problems · ~60h · difficulty: mixed · Last verified
Two Pointers: hash-map variant of the two-pointer mental model — looking for a complementary value as you scan.
Two Pointers: classic converging pointers from both ends. The shape every string-checking problem reduces to.
Two Pointers: shrink from the side with the shorter wall. The 'why this side?' question is the whole interview.
Two Pointers: fix one anchor, then collapse two pointers on the remainder. The bridge from O(n^3) to O(n^2).
Sliding Window: variable-width window with a set. Master the 'shrink left until valid' loop before all other window problems.
Sliding Window: fixed-width window with a frequency counter. Different shape, same window discipline.
Sliding Window (Kadane's variant): expand when the running sum helps, reset when it hurts. The simplest dynamic window.
Hash Map: set-membership in O(1). The simplest possible application — practice narrating space-for-time.
Hash Map: frequency-counter template. The same template you'll reuse in ten more problems this month.
Hash Map: keyed bucketing. Build a canonical key from the input, group by key. Trade-off between sorted-key and count-tuple is the interview probe.
Hash Map + bucket sort: count, then bucket by frequency. Beats the heap solution at O(n).
Hash Map: prefix-sum + complement lookup. The 'two-sum on prefix sums' trick — unlocks a dozen subarray problems.
Hash Map: O(n) via 'only start counting at sequence heads'. The trick is the guard, not the data structure.
Binary Search: the canonical lo/hi/mid template. Drill until the off-by-one boundaries are reflex.
Binary Search: compare mid to RIGHT instead of target. First problem that breaks the 'binary search needs a target' frame.
Binary Search: decide which half is sorted, check if target lives there, recurse. The four branches are fiddly — write them out.
Binary Search: search on the ANSWER, not an index. Once you see it once, you spot it in capacity-to-ship and split-array-largest-sum.
BFS: queue + snapshot size per level. The canonical level-by-level template — reused in graphs verbatim.
BFS (or DFS): grid traversal with visited marking. The flood-fill template that powers every 'count regions' problem.
BFS: queue + hash map (old -> new) acting as both visited set AND clone lookup. Two jobs, one data structure.
BFS: shortest path in an implicit graph. Build neighbors on the fly via wildcard patterns — the trick that turns O(n^2) into O(n).
DFS: recursive height computation. The simplest recursion on trees — base = null, recurse = children.
DFS: cycle detection in a directed graph via three-color marking. The shape of every dependency-resolution interview question.
DFS: reverse the question — instead of 'which cells can flow out', ask 'which cells can the ocean reach inward'. Two DFS, then intersect.
DFS: pass (lo, hi) bounds down the recursion. The shortcut of comparing each node to parent only is the WRONG answer — interviewers test for it.
Backtracking: include/exclude tree. The simplest backtrack — every other backtracking problem is a richer version of this choice.
Backtracking: swap-in-place to generate every ordering. The 'used set' alternative is also valid — defend whichever you pick.
Backtracking: recurse with a start-index to forbid duplicates. The start-index trick is the only difference from permutations.
Backtracking: grid DFS with mark-and-unmark. The unmark on the way back up is the part beginners forget.
Backtracking: column + diagonal sets pruned per row. The hard version: prove your pruning is correct, don't just trust the recursion.
Greedy: maintain the farthest reachable index. The DP exists but greedy is the answer — name the swap explicitly.
Greedy: BFS-like layers — expand the 'current jump' window until it closes, then bump the count.
Greedy: if total gas >= total cost, an answer exists; restart from i+1 whenever the tank goes negative. Two passes collapse to one.
Greedy: cooldown math — most-frequent task sets the floor. The formula derivation is what interviewers want you to walk through.
1D DP: f(n) = f(n-1) + f(n-2). The simplest possible recurrence — drill the bottom-up form before any harder DP.
1D DP: f(i) = max(f(i-1), f(i-2) + nums[i]). The 'rob or skip' decision is the substrate for every linear DP.
1D DP: unbounded knapsack. dp[amount] = min over coins of dp[amount - coin] + 1. Practice narrating WHY it's not greedy.
1D DP: O(n^2) baseline first. Save the O(n log n) patience-sort trick for the follow-up.
1D DP: dp[i] = can-we-segment prefix of length i. Each position checks 'does some valid word end here AND was the prefix before it segmentable?'
1D DP (knapsack flavor): can we hit target = sum/2? The 0/1 knapsack reduction is the whole interview signal.
2D DP: grid count — dp[i][j] = dp[i-1][j] + dp[i][j-1]. The simplest 2D recurrence — burn the bottom-up form into reflex.
2D DP: same recurrence as unique-paths, swap count for min(). Practice articulating which DP transitions transfer between problems.
2D DP (or expand-around-center): the DP fills a is_palindrome[i][j] table. Be ready to defend either approach — interviewers ask why one beats the other.
2D DP on intervals. dp[i][j] = longest palindrome in s[i..j]. The classic 'expand the interval' DP shape.
2D DP: dp[i][j] = side-length of largest square ending here = 1 + min of three neighbors. Beautiful recurrence — derive it on the spot.
Heap: max-heap, pop two, push the difference. The simplest possible heap problem — train the 'do I need to keep the K largest?' instinct.
Heap: min-heap of size k. Trade-off vs quickselect is the whole conversation — be ready to defend both choices out loud.
Heap: max-heap of size k, kicked by distance. Same skeleton as kth-largest with a custom comparator.
Heap: two heaps (max-heap of lower half, min-heap of upper half), kept balanced. The two-heap pattern unlocks sliding-window median too.
Trie + Backtracking: build a Trie of words once, then DFS the board with the Trie as a multi-target pruner. Capstone — combines two patterns.
Ready to drill these live?
Get the AI copilot in your ear during real interviews. Real-time transcription. Streaming answers. Post-call scorecard.
Download the desktop app →