There are almost 3,000 problems on LeetCode. Blind 75, Blind 150, and other curated lists promise confidence—but the underlying structure matters more than any single list. After tagging problems by core technique, one discovery stood out: just 8 patterns cover over 2,000 problems. Not 80. Not 20. Eight.
The 8 Patterns at a Glance
| # | Pattern | Problems | Cumulative |
|---|---|---|---|
| 1 | Two Pointers | 244 | 244 |
| 2 | Sliding Window | 164 | 408 |
| 3 | Modified Binary Search | 256 | 664 |
| 4 | Hash Map / Hash Set | 471 | 1,135 |
| 5 | Monotonic Stack / Prefix Sum | 170 | 1,305 |
| 6 | BFS / DFS | 167 | 1,472 |
| 7 | Memoization (DP) | 376 | 1,848 |
| 8 | Heap / Priority Queue | 156 | 2,004 |
That is 2,004 problems covered with eight techniques. Counts come from community tags and problem metadata on LeetCode—your mileage may vary slightly as tags update, but the order of magnitude holds.
1. Two Pointers
Problems covered: ~244
Two pointers turn many O(n^2) approaches into O(n). You place two index markers and move them based on a condition. Movement stays one-directional, so you avoid redundant work.
How to Recognize It
- Input is a sorted array or list
- You need a pair or triplet satisfying a condition
- In-place operations
- Keywords: “remove duplicates,” “two numbers that add up to,” “container with most water”
Three Flavors
Opposite direction — One pointer at the start, one at the end; they move toward each other (e.g., two-sum in a sorted array).
Same direction, different speeds — Fast and slow pointers (e.g., cycle detection in a linked list).
Partitioning — One pointer tracks the write position, the other scans (e.g., move zeros to the end).
Practice Problems
- 167. Two Sum II – Input Array Is Sorted — opposite direction, sorted array
- 15. 3Sum — fix one index, two-pointer scan on the rest
- 11. Container With Most Water — shrink from both ends
- 283. Move Zeroes — partitioning / in-place
2. Sliding Window
Problems covered: ~164 (cumulative with pattern 1: 408)
A sliding window is a contiguous slice of your input. You expand to explore and shrink to restore a condition. Each element is touched at most twice, so you often get O(n) instead of brute-force O(n^2).
How to Recognize It
- “Contiguous subarray” or “substring“
- “Longest or shortest that satisfies…”
- “At most K” distinct elements, characters, or replacements
- Linear input (array or string)
Fixed vs Dynamic Window
Fixed window — Size is given; slide it across (e.g., maximum average subarray of length k).
Dynamic window — Expand the right edge until a condition breaks, then shrink from the left. Track the best answer as you go.
Practice Problems
- 643. Maximum Average Subarray I — fixed window
- 3. Longest Substring Without Repeating Characters — dynamic window
- 424. Longest Repeating Character Replacement — window with a replacement budget
- 76. Minimum Window Substring — minimize window size
3. Modified Binary Search
Problems covered: ~256 (cumulative: 664)
Binary search is not only “find a value in a sorted array.” The powerful form is searching an answer space: you binary-search on the answer itself, not just on array indices.
How to Recognize It
- Input is sorted (classic case)
- “Find the minimum value that satisfies…” or “maximum such that…”
- “Can you do X within Y?” → binary search on Y
If everything below a threshold fails and everything at or above passes, you can binary-search that boundary.
Practice Problems
- 875. Koko Eating Bananas — search on answer space (eating speed)
- 74. Search a 2D Matrix — treat 2D as sorted 1D or row/column binary search
- 162. Find Peak Element — condition-based search without fully sorted input
- 1011. Capacity To Ship Packages Within D Days — feasibility + binary search on capacity
4. Hash Map / Hash Set
Problems covered: ~471 (cumulative: 1,135)
This pattern appears in roughly one in five LeetCode problems. The idea: trade space for time. Store what you have seen in a hash map for O(1) lookups and drop nested O(n^2) scans.
How to Recognize It
- “Find duplicates,” “count frequencies,” “group elements”
- “Does this exist?” or “find the complement“
- Inner loop of brute force is “search for something” → often replace with a map
Bijection (Two-Way Mapping)
Some problems need each key to map to exactly one value and vice versa. Word Pattern is the classic example: one map is not enough if you only check one direction.
Practice Problems
- 1. Two Sum — complement lookup
- 128. Longest Consecutive Sequence — set + existence checks
- 290. Word Pattern — bijection mapping
- 169. Majority Element — frequency counting
5. Monotonic Stack / Prefix Sum
Problems covered: ~170 (cumulative: 1,305)
Both ideas share one philosophy: preprocess once, answer queries fast.
Prefix Sum
Build a running-sum array; range sums become O(1) via subtraction. Combine prefix sums with a hash map for problems like “number of subarrays summing to k.”
Signals: “subarray sum,” “range sum,” “cumulative.”
Monotonic Stack
Keep the stack in sorted order (increasing or decreasing). Pop elements that break the invariant; popped items often “find” their next greater or next smaller element.
Signals: “next greater element,” “daily temperatures,” “largest rectangle in histogram.”
Practice Problems
- 724. Find Pivot Index — basic prefix sum
- 560. Subarray Sum Equals K — prefix sum + hash map
- 303. Range Sum Query – Immutable — textbook prefix sum
- 238. Product of Array Except Self — prefix / suffix product
- 739. Daily Temperatures — monotonic stack
- 84. Largest Rectangle in Histogram — monotonic stack (advanced)
6. BFS / DFS
Problems covered: ~167 (cumulative: 1,472)
DFS goes deep first (recursion or explicit stack): paths, cycles, tree properties.
BFS goes level by level (queue): shortest path in unweighted graphs, level-order processing.
How to Recognize It
- Trees, graphs, grids, matrices
- “Connected components,” “number of islands,” “shortest path” (often BFS)
- “Prerequisites,” “dependency order” → topological sort
Quick Rule of Thumb
- Shortest path or level-by-level → BFS
- All paths, cycles, deep structure → DFS
- Dependencies → topological sort (often BFS with in-degree)
Practice Problems
- 104. Maximum Depth of Binary Tree — simple DFS/BFS
- 200. Number of Islands — grid DFS/BFS
- 994. Rotting Oranges — multi-source BFS
- 207. Course Schedule — cycle detection / topological sort
7. Memoization (Dynamic Programming)
Problems covered: ~376 (cumulative: 1,848)
If a problem breaks into overlapping subproblems, cache results instead of recomputing. That is memoization—the heart of most DP on LeetCode.
How to Recognize It
- “Number of ways,” “minimum cost,” “maximum profit,” “can you reach…”
- Choices at each step; answer for size n built from smaller sizes
Top-down: recursion + cache. Bottom-up: fill a table iteratively. Both are valid; top-down is often easier to reason about.
DP has sub-patterns (1D/2D, knapsack, intervals)—but recognition always starts with overlapping subproblems and optimal substructure.
Practice Problems
- 70. Climbing Stairs — simplest 1D DP
- 322. Coin Change — unbounded knapsack style
- 1143. Longest Common Subsequence — 2D DP
- 198. House Robber — choice at each house
8. Heap / Priority Queue
Problems covered: ~156 (cumulative: 2,004)
A min-heap (or max-heap) gives O(1) access to the extreme element and O(\log n) insert/delete. When you repeatedly need the smallest or largest from a changing set, use a heap.
How to Recognize It
- “Kth largest” / “Kth smallest”
- “Top K frequent”
- “Merge K sorted lists”
- Streaming median (often two heaps)
Practice Problems
- 215. Kth Largest Element in an Array — core heap pattern
- 347. Top K Frequent Elements — heap + frequency map
- 295. Find Median from Data Stream — two heaps
- 1046. Last Stone Weight — repeated extract-max
Bonus: What About Greedy?
Greedy does not appear as a separate “mechanical” pattern here on purpose. The other patterns (except hash maps as pure structure) each map to a repeatable template. Greedy is a decision paradigm—the implementation might use sorting, two pointers, heaps, or something else. Roughly 285 LeetCode problems are tagged greedy; mastering the eight patterns above gives you the machinery to implement most of them. The hard part of greedy is often the proof, not the code.
What Now? How to Practice
Knowing the patterns is step one. Practice deliberately:
- One pattern at a time — avoid jumping randomly between topics.
- Four or five problems per pattern before moving on—start with the links above.
- Recognition first — before coding, name the pattern and why it fits.
- Track progress — use a structured plan so you are not grinding blindly.
For a guided roadmap that picks problems by pattern, company frequency, and your timeline, see Smart Interview Grind. For all curated links and resources in one place, visit all my helpful resources.
Video Explanation
If you want personalized help choosing problems or structuring prep, schedule a one-on-one session.
More solutions and patterns: GitHub (Java solutions).