14 Coding Patterns That Solve 80% of Interview Problems
Instead of memorising 500 LeetCode solutions, learn 14 patterns. Recognise the pattern and you can derive the solution from first principles.
14 Coding Patterns That Solve 80% of Interview Problems
The best way to prepare for coding interviews isn't to solve 500 LeetCode problems. It's to recognise the 14 patterns that most problems reduce to.
The 14 Patterns
| # | Pattern | Example Problems |
|---|---|---|
| 1 | Two Pointers | Two Sum (sorted), Container With Most Water |
| 2 | Sliding Window | Longest Substring Without Repeating Characters |
| 3 | Fast & Slow Pointers | Linked List Cycle, Find Middle of List |
| 4 | Merge Intervals | Merge Intervals, Insert Interval |
| 5 | Cyclic Sort | Find All Missing Numbers, Find Duplicate Number |
| 6 | In-Place Linked List Reversal | Reverse Linked List, Reverse Sub-list |
| 7 | Tree BFS | Binary Tree Level Order Traversal |
| 8 | Tree DFS | Path Sum, All Root-to-Leaf Paths |
| 9 | Two Heaps | Find Median from Data Stream |
| 10 | Subsets (Backtracking) | Subsets, Permutations, Combinations |
| 11 | Modified Binary Search | Search in Rotated Array, Find Min in Rotated Array |
| 12 | Top-K Elements | K Largest Elements, K Most Frequent |
| 13 | K-Way Merge | Merge K Sorted Lists |
| 14 | Dynamic Programming | Coin Change, Longest Common Subsequence |
How to identify patterns
Sliding Window → "subarray/substring with constraint" + contiguous elements
Two Pointers → sorted array + target sum, or palindrome/reverse check
Tree DFS → process individual node, return something to parent (path problems)
Tree BFS → level-by-level, find something at a specific depth
Top-K → K largest/smallest, and sort is too slow → min-heap of size K
DP → count ways / optimal value + overlapping subproblems
Example: how to read a problem
"Find the length of the longest substring without repeating characters"
- "substring" → contiguous → sliding window
- "without repeating" → constraint on window contents
- Template: expand right pointer, shrink left pointer when constraint violated
Once you see the pattern, the code writes itself.