This site uses one functional cookie to keep feature rollouts consistent for you. Nothing is set until you choose. See the privacy notice.
There are thousands of LeetCode problems and about two dozen ideas behind them. This is a playbook for learning to see which idea a problem wants from the way it's worded, then practising it until the code comes without thinking: 23 patterns, 223 hand-picked problems, a recognition drill, and a review schedule that brings problems back before they fade.
Nothing due. Rate a problem after you solve it and it comes back here on a 1, 3, 7, 14, 30, 60 day ladder, which is how a solution goes from "I've seen this" to "I can write this".
Paste a problem statement. The finder does what I want to do in my head on every read: spot the handful of phrases that give the pattern away. It's a phrase count, not magic, so treat it as a second opinion.
A judge gets through roughly 108 simple operations in the time limit, so the largest n in the constraints tells you which complexities are even allowed before you've thought about the problem.
| n up to | Budget | Typical patterns |
|---|---|---|
| 12 | O(n!) | Permutations, brute-force backtracking over every ordering |
| 25 | O(2^n) | Subsets, backtracking with pruning, bitmask DP |
| 500 | O(n^3) | Interval DP, triple loops, Floyd–Warshall |
| 10,000 | O(n^2) | 2D DP over pairs, nested loops, all pairs of elements |
| 1,000,000 | O(n log n)(yours) | Sorting, heaps, binary search inside a loop, divide and conquer |
| 100,000,000 | O(n) | One pass: hash map, two pointers, sliding window, prefix sums, monotonic stack |
| anything | O(log n) | Binary search on the answer, or a closed-form maths result |
23 patterns in the order they build on each other. Each page has the wording that gives it away, a template to write from memory, and a ladder of LeetCode problems from easy to hard.
Remember what you've seen so you never look for it twice.
0 of 9 solved
Two indices, each move ruling out a whole row of pairs.
0 of 9 solved
Grow the right edge, shrink the left, never restart.
0 of 10 solved
Precompute running totals once, answer any range in O(1).
0 of 8 solved
The most recent unfinished thing is the next one to finish.
0 of 8 solved
If you can tell which half the answer is in, throw the other half away.
0 of 11 solved
Draw the arrows, then rewire them in the right order.
0 of 12 solved
Keep a stack in sorted order; whatever you pop just found its answer.
0 of 8 solved
Trust the recursion: solve it for the children, combine at the parent.
0 of 12 solved
Process the tree one level at a time.
0 of 8 solved
Left is smaller, right is bigger: use it to skip half the tree.
0 of 9 solved
Always know the smallest (or biggest) thing, cheaply, while things keep changing.
0 of 10 solved
Sort by start, then each interval only has to look at the last one kept.
0 of 9 solved
Share the prefixes so every word that starts the same way walks the same path.
0 of 8 solved
Choose, explore, un-choose. Prune anything that can't work.
0 of 13 solved
Grids and networks are graphs. Mark what you've visited and flood outward.
0 of 11 solved
Things with prerequisites: peel off whatever has nothing left blocking it.
0 of 7 solved
Merge groups as connections arrive, and ask which group anything is in.
0 of 8 solved
BFS with a heap: always expand the cheapest place you can reach next.
0 of 7 solved
Take the locally best move, but only once you can argue it never hurts.
0 of 11 solved
Define what dp[i] means, find how it depends on smaller i, then fill it in order.
0 of 13 solved
Two strings, a grid, or an index plus a budget: the state needs two numbers.
0 of 14 solved
XOR cancels pairs, n & (n - 1) drops the lowest set bit.
0 of 8 solved