The 500-Problem Trap
A common failure mode in coding interview prep: candidates grind through 500 LeetCode problems, feel ready, then walk into an interview and freeze on a problem that's a 10% twist on something they've seen before.
The diagnosis is wrong. They didn't fail because they hadn't seen enough problems. They failed because they'd been pattern-matching on problem statements instead of solution structures.
There's a small set of underlying patterns — maybe 14 to 18 of them, depending on how you count — that show up across the vast majority of coding-interview questions. Internalize the patterns and you can adapt to any specific problem. Memorize the problems and you're brittle.
The Patterns That Actually Matter
Here are the patterns worth deeply understanding. They're not in priority order — frequency varies by company.
1. Two Pointers
Use case: searching, comparing, or merging in a sorted (or partially sorted) array. Sub-variants: opposite-direction, same-direction (sliding window), fast-and-slow.
Recognize when: the array is sorted, you're looking for a pair/triplet, or you're tracking two positions through one structure.
2. Sliding Window
A specialization of two pointers. Maintain a window over a contiguous range, expand and contract based on a condition.
Recognize when: the problem asks for the longest/shortest/most-of-something in a contiguous subarray or substring.
3. Fast & Slow Pointers (Floyd's Cycle Detection)
Two pointers moving at different speeds through a linked structure.
Recognize when: linked lists, cycle detection, finding the middle, or detecting palindromes in a stream.
4. Merge Intervals
Sort intervals, then merge overlapping ones in a single pass.
Recognize when: any problem mentioning intervals, ranges, meetings, or scheduling.
5. Cyclic Sort
When numbers in an array are in a known range (often 1 to N), sort by placing each number at its correct index.
Recognize when: the problem mentions a fixed range of integers and asks you to find a missing/duplicate number with O(1) extra space.
6. In-place Reversal of a Linked List
Reverse all or part of a linked list without allocating new nodes.
Recognize when: linked list manipulation that doesn't fit two-pointers cleanly.
7. Tree BFS
Level-order traversal using a queue.
Recognize when: you need anything by level (zigzag traversal, right-side view, level averages).
8. Tree DFS (with backtracking)
Recursion with explicit state passed down.
Recognize when: path sums, root-to-leaf problems, tree-construction problems.
9. Topological Sort
Order nodes in a DAG such that every edge goes from earlier to later.
Recognize when: dependencies, course schedules, build orders, or any "what order should I do these in" problem.
10. Dynamic Programming
A pattern of patterns. Sub-categories: 0/1 knapsack, unbounded knapsack, longest common subsequence, fibonacci-style.
Recognize when: the problem has overlapping subproblems and optimal substructure. The brute-force solution is exponential and you can see repeated state.
11. Modified Binary Search
Binary search but the array isn't strictly sorted (rotated, bitonic, or you're searching for a condition rather than a value).
Recognize when: O(log n) is hinted at but the array shape is unusual.
12. Graph Traversal (BFS/DFS)
The graph version of tree traversal, with cycle detection.
Recognize when: anything modeled as nodes and edges that isn't a tree.
13. Backtracking
Try a choice, recurse, undo if it fails.
Recognize when: combinatorial problems — permutations, combinations, N-queens, sudoku, generate-all-X.
14. Top K Elements
Use a heap to maintain the K best/worst as you scan.
Recognize when: "find the K most frequent / largest / smallest."
How to Practice
Pick one pattern. Solve 5–8 problems in that pattern only, in one sitting, without context-switching to other patterns. The point is to build the muscle memory of recognizing the pattern from the problem statement.
After you've done all 14, go back and re-solve a mix without telling yourself which pattern applies. Force yourself to identify it from the problem alone. That's the skill that survives the interview.
What's Next on This Site
Future posts: pattern-by-pattern deep dives, decision trees for picking the right pattern under pressure, and how to communicate your approach during the interview itself.
