Coding Patterns You Should Actually Drill
The fastest way to improve at coding interviews is not more problems — it's recognizing which pattern a problem belongs to within the first 60 seconds. The patterns below cover roughly 80% of medium-difficulty interview questions.
The core 15 patterns
- Two Pointers — sorted arrays, palindrome checks, pair sums.
- Sliding Window — longest/shortest substring, fixed-size subarrays.
- Fast & Slow Pointers — cycle detection, finding the middle of a linked list.
- Merge Intervals — overlapping intervals, meeting rooms.
- Cyclic Sort — finding missing numbers when values are bounded.
- In-place Linked List Reversal — reverse a list, reverse in groups.
- Tree BFS — level order traversal, zigzag, right-side view.
- Tree DFS — path sum, lowest common ancestor, serialization.
- Two Heaps — find the median of a stream, scheduling.
- Subsets / Permutations — generate all subsets, all anagrams.
- Modified Binary Search — search in rotated array, find peak.
- Top K Elements — k closest points, k frequent elements.
- K-way Merge — merge k sorted lists, smallest range.
- Topological Sort — course schedule, alien dictionary.
- Dynamic Programming — knapsack, LCS, edit distance.
Pattern recognition cheat sheet
If the problem mentions… try this pattern first:
| Signal in the problem | Pattern |
|---|---|
| "Sorted array" + "find pair / triple" | Two Pointers |
| "Longest / shortest substring" | Sliding Window |
| "Cycle in linked list" | Fast & Slow Pointers |
| "Merge / overlap intervals" | Merge Intervals |
| "Numbers in 1..N, missing or duplicate" | Cyclic Sort |
| "Reverse a linked list (in groups)" | In-place Reversal |
| "Level-by-level / shortest path on grid" | Tree/Graph BFS |
| "All paths / all combinations" | Tree DFS / Backtracking |
| "Median of a stream" | Two Heaps |
| "All subsets / permutations" | Subsets |
| "Sorted / rotated array search" | Modified Binary Search |
| "Top K / K smallest / K closest" | Top K (Heap) |
| "Merge K sorted things" | K-way Merge |
| "Dependency / order / prerequisite" | Topological Sort |
| "Min/max with overlapping subproblems" | Dynamic Programming |
This table covers ~80% of medium-difficulty interview problems. Memorize it.
How to drill
For each pattern, do this loop:
- Read the canonical example. Understand why the pattern works, not just the steps.
- Solve 3–5 variations. Start medium, push to hard.
- Re-derive without looking. A week later, can you write the solution from scratch?
- Time-box. 25 minutes per problem. If you blow past it, look at the solution, understand it, then re-solve in 24 hours.
If a pattern stops feeling automatic after a week of break, that's normal. Spaced repetition keeps it sharp.
Common mistakes
- Memorizing solutions instead of patterns. Interviewers will tweak the constraints. If you only know the exact problem, you're stuck.
- Ignoring complexity analysis. Almost every interviewer asks. Practice stating time/space before you start coding.
- Coding silently. Narrate your reasoning. The interview is as much about communication as correctness.