Step 2 of 2 · your path
DSA, Intermediate
You have the toolkit. Now learn the structures and techniques that cover most real interview questions: trees and BSTs, graphs and grid BFS, topological sort, backtracking, DP, greedy, tries, the monotonic stack, bit tricks and math.
Your progress
0 / 22 done
Up next
Trees
23 min read · 13 exercises
The order I'd read them in
About 12 h 7 min of reading. Tick off what you've read, it is remembered on this device.
- TreesA linked list that's allowed to branch — and the three orders you can walk it in.
- BST operations and ordered dataInsert, delete, successor, kth smallest and an iterator — and the honest truth about balancing and about a language with no TreeMap.
14 exercises
- Tree problems in depthConstruction, LCA, balance and serialization — the four questions traversal alone doesn't answer.
21 exercises
- 8 tests · intermediate
- 8 tests · intermediate
- 7 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 7 tests · intermediate
- 8 tests · advanced
- 8 tests · advanced
- Heaps & priority queuesYou don't need the whole thing sorted — you need the extreme value, fast, repeatedly.
24 exercises
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · intermediate
- 11 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 9 tests · intermediate
- 9 tests · advanced
- 9 tests · advanced
- Graphs: representation & traversalA tree is a graph with no cycles and one root — now drop both restrictions.
- BFS on grids and implicit graphsA grid, a word list and a lock are all the same graph: states, a rule for the next states, and a queue that finishes one distance before starting the next.
20 exercises
- 8 tests · beginner
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 10 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 9 tests · advanced
- 8 tests · advanced
- 9 tests · advanced
- 8 tests · intermediate
- 8 tests · intermediate
- Graph problemsComponents, cycles, colouring, trees and reachability: the same traversal each time, with a different thing to track.
15 exercises
- 8 tests · intermediate
- 8 tests · advanced
- 9 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 10 tests · intermediate
- 9 tests · advanced
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- Topological patternsAny problem phrased as "X must come before Y" is a DAG asking to be linearized.
- BacktrackingTry a choice, recurse, undo the choice — DFS over a tree of decisions instead of a graph.
- Dynamic programming: 1DRecursion, minus the part where you solve the same subproblem twice.
17 exercises
- 8 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- Dynamic programming: 2DSame idea as 1D, one more dimension — a grid table instead of a row.
18 exercises
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 9 tests · intermediate
- 8 tests · intermediate
- 10 tests · advanced
- 9 tests · intermediate
- 9 tests · intermediate
- 7 tests · intermediate
- 7 tests · intermediate
- 7 tests · intermediate
- 7 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 9 tests · advanced
- DP state machines and the knapsack familyWhen one number per position cannot remember enough, keep one number per mode, and let the loop order say what you are counting.
18 exercises
- 8 tests · intermediate
- 8 tests · beginner
- 7 tests · intermediate
- 7 tests · intermediate
- 7 tests · intermediate
- 7 tests · advanced
- 7 tests · advanced
- 7 tests · intermediate
- 7 tests · intermediate
- 9 tests · intermediate
- 7 tests · intermediate
- 7 tests · advanced
- 8 tests · intermediate
- 7 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 7 tests · intermediate
- 7 tests · intermediate
- Greedy algorithmsThe best DP alternative — when the locally best choice happens to be globally best too.
16 exercises
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 7 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- IntervalsEvery interval question starts the same way: sort by start time. Then it's bookkeeping.
- Bit manipulationA small, fixed toolkit of tricks that turn up constantly once you recognize them.
29 exercises
- 10 tests · beginner
- 8 tests · intermediate
- 8 tests · beginner
- 8 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · beginner
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · beginner
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · intermediate
- 7 tests · intermediate
- 7 tests · beginner
- 8 tests · advanced
- 7 tests · beginner
- 8 tests · intermediate
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · intermediate
- 7 tests · beginner
- Matrix problemsA grid is an array of arrays — every trick here is index bookkeeping, done carefully.
18 exercises
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · beginner
- 7 tests · intermediate
- 8 tests · beginner
- 8 tests · beginner
- 8 tests · beginner
- 7 tests · beginner
- 7 tests · advanced
- TriesStore the string as a path, not a value — and every prefix question becomes a walk instead of a scan.
- Monotonic stack & queue in depthThrow away every element that can never win again — what survives is already sorted.
15 exercises
- Math for interviewsSmall, exact facts about numbers: how Euclid, the sieve, modular arithmetic and a few counting identities turn huge inputs into short loops, and where JavaScript's numbers stop being exact.
19 exercises
- 8 tests · beginner
- 13 tests · beginner
- 8 tests · beginner
- 6 tests · beginner
- 8 tests · intermediate
- 8 tests · intermediate
- 11 tests · intermediate
- 8 tests · intermediate
- 7 tests · beginner
- 11 tests · advanced
- 10 tests · intermediate
- 12 tests · intermediate
- 11 tests · intermediate
- 8 tests · beginner
- 9 tests · beginner
- 9 tests · intermediate
- 9 tests · beginner
- 11 tests · advanced
- 23 tests · advanced
- Design and simulation problemsTurn a paragraph of requirements into a small machine: state, operations, costs, and the sentences that stay true.
16 exercises
- 8 tests · beginner
- 8 tests · beginner
- 9 tests · intermediate
- 7 tests · intermediate
- 7 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 7 tests · beginner
- 8 tests · advanced
- 8 tests · advanced
- 7 tests · beginner
- 7 tests · beginner
- 7 tests · intermediate
- 7 tests · intermediate
- Divide and conquer and selectionCut the input in two, solve each half, and the whole difficulty moves into one question: what can the answer be that neither half sees?
15 exercises
- 9 tests · advanced
- 8 tests · advanced
- 8 tests · advanced
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · advanced
- 12 tests · advanced
- 10 tests · advanced
- 8 tests · intermediate
- 10 tests · intermediate
- 10 tests · intermediate
- 9 tests · intermediate
- 8 tests · advanced
- 9 tests · intermediate
- 9 tests · intermediate
- Randomization and samplingMake the generator a parameter, count the outcomes, and prove every outcome gets its fair share before you trust the code.
17 exercises
- 9 tests · beginner
- 8 tests · beginner
- 7 tests · intermediate
- 8 tests · intermediate
- 7 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · intermediate
- 9 tests · intermediate
- 8 tests · advanced
- 8 tests · advanced
Practice at this level
Every exercise opens in the editor with tests you can run.
- Greedy algorithms · 8 tests
- Greedy algorithms · 8 tests
- Greedy algorithms · 8 tests
- Greedy algorithms · 8 tests
- Bit manipulation · 10 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 9 tests
- Bit manipulation · 9 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Backtracking · 8 tests
- Bit manipulation · 8 tests
- Tries · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Graphs: representation · 8 tests
- Graphs: representation · 8 tests
- Graphs: representation · 8 tests
- Graphs: representation · 8 tests
- Graph problems · 8 tests
- Graphs: representation · 8 tests
- Graph problems · 8 tests
- Graph problems · 9 tests
- Graph problems · 9 tests
- Graph problems · 8 tests
- Topological patterns · 8 tests
- Topological patterns · 8 tests
- Topological patterns · 8 tests
- Topological patterns · 9 tests
- Topological patterns · 9 tests
- Topological patterns · 9 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 2D · 8 tests
- DP: 2D · 8 tests
- DP: 2D · 8 tests
- DP: 2D · 8 tests
- DP: 2D · 8 tests
- DP: 2D · 9 tests
- DP: 2D · 8 tests
- DP: 2D · 10 tests
- DP: 2D · 9 tests
- DP: 2D · 9 tests
- Backtracking · 8 tests
- Backtracking · 8 tests
- Backtracking · 8 tests
- Backtracking · 8 tests
- Backtracking · 8 tests
- Backtracking · 8 tests
- Intervals · 8 tests
- Intervals · 8 tests
- Intervals · 8 tests
- Intervals · 8 tests
- Matrix problems · 8 tests
- Matrix problems · 8 tests
- Matrix problems · 8 tests
- Matrix problems · 8 tests
- Matrix problems · 9 tests
- Matrix problems · 8 tests
- Matrix problems · 9 tests
- Matrix problems · 8 tests
- Tries · 8 tests
- Tries · 8 tests
- Tries · 8 tests
- Monotonic stack & queue · 8 tests
- Monotonic stack & queue · 8 tests
- Monotonic stack & queue · 8 tests
- Monotonic stack & queue · 8 tests
- Monotonic stack & queue · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Intervals · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 8 tests
- Trees · 8 tests
- Trees · 8 tests
- Trees · 8 tests
- Trees · 8 tests
- Trees · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Trees · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Greedy algorithms · 8 tests
- Backtracking · 9 tests
- Backtracking · 11 tests
- Backtracking · 7 tests
- Backtracking · 7 tests
- Backtracking · 9 tests
- Bit manipulation · 7 tests
- Bit manipulation · 7 tests
- Bit manipulation · 8 tests
- Bit manipulation · 7 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 8 tests
- Bit manipulation · 7 tests
- BST operations · 9 tests
- BST operations · 9 tests
- BST operations · 9 tests
- BST operations · 9 tests
- BST operations · 9 tests
- BST operations · 8 tests
- BST operations · 7 tests
- BST operations · 9 tests
- BST operations · 9 tests
- BST operations · 8 tests
- BST operations · 9 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 8 tests
- DP: 1D · 9 tests
- DP: 2D · 7 tests
- DP: 2D · 7 tests
- DP: 2D · 7 tests
- DP: 2D · 7 tests
- DP: 2D · 8 tests
- DP: 2D · 8 tests
- DP: 2D · 8 tests
- DP: 2D · 9 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- DP state machines · 7 tests
- Graph problems · 10 tests
- Graph problems · 9 tests
- Graph problems · 8 tests
- Graph problems · 8 tests
- Graph problems · 9 tests
- Graph problems · 8 tests
- Graphs: representation · 10 tests
- Graphs: representation · 8 tests
- Graphs: representation · 9 tests
- Graphs: representation · 9 tests
- Graphs: representation · 9 tests
- Graphs: representation · 9 tests
- Graphs: representation · 8 tests
- Greedy algorithms · 8 tests
- Greedy algorithms · 8 tests
- Greedy algorithms · 8 tests
- Greedy algorithms · 8 tests
- Greedy algorithms · 7 tests
- Greedy algorithms · 8 tests
- BFS on grids · 8 tests
- BFS on grids · 8 tests
- BFS on grids · 8 tests
- BFS on grids · 9 tests
- BFS on grids · 10 tests
- BFS on grids · 9 tests
- BFS on grids · 9 tests
- BFS on grids · 9 tests
- BFS on grids · 8 tests
- BFS on grids · 9 tests
- BFS on grids · 8 tests
- BFS on grids · 9 tests
- BFS on grids · 8 tests
- BFS on grids · 8 tests
- Heaps & priority queues · 11 tests
- Heaps & priority queues · 9 tests
- Heaps & priority queues · 8 tests
- Heaps & priority queues · 9 tests
- Heaps & priority queues · 9 tests
- Heaps & priority queues · 9 tests
- Heaps & priority queues · 9 tests
- Intervals · 8 tests
- Intervals · 8 tests
- Intervals · 8 tests
- Intervals · 7 tests
- Intervals · 8 tests
- Math for interviews · 8 tests
- Math for interviews · 13 tests
- Math for interviews · 8 tests
- Math for interviews · 6 tests
- Math for interviews · 8 tests
- Math for interviews · 8 tests
- Math for interviews · 11 tests
- Math for interviews · 7 tests
- Math for interviews · 11 tests
- Math for interviews · 10 tests
- Math for interviews · 12 tests
- Math for interviews · 11 tests
- Math for interviews · 11 tests
- Math for interviews · 23 tests
- Matrix problems · 8 tests
- Matrix problems · 7 tests
- Matrix problems · 8 tests
- Matrix problems · 8 tests
- Matrix problems · 8 tests
- Matrix problems · 7 tests
- Matrix problems · 7 tests
- Monotonic stack & queue · 9 tests
- Monotonic stack & queue · 8 tests
- Monotonic stack & queue · 9 tests
- Monotonic stack & queue · 8 tests
- Monotonic stack & queue · 9 tests
- Monotonic stack & queue · 8 tests
- Monotonic stack & queue · 9 tests
- Monotonic stack & queue · 9 tests
- Topological patterns · 9 tests
- Topological patterns · 9 tests
- Topological patterns · 10 tests
- Topological patterns · 9 tests
- Topological patterns · 9 tests
- Tree problems in depth · 7 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 7 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Tree problems in depth · 8 tests
- Trees · 8 tests
- Trees · 8 tests
- Trees · 8 tests
- Trees · 7 tests
- Trees · 7 tests
- Trees · 8 tests
- Trees · 7 tests
- Tries · 8 tests
- Tries · 8 tests
- Tries · 8 tests
- Tries · 8 tests
- Tries · 9 tests
- Design & simulation · 8 tests
- Design & simulation · 9 tests
- Design & simulation · 7 tests
- Design & simulation · 7 tests
- Design & simulation · 8 tests
- Design & simulation · 8 tests
- Design & simulation · 8 tests
- Design & simulation · 7 tests
- Design & simulation · 8 tests
- Design & simulation · 8 tests
- Design & simulation · 7 tests
- Design & simulation · 7 tests
- Design & simulation · 7 tests
- Design & simulation · 7 tests
- Divide and conquer · 8 tests
- Divide and conquer · 9 tests
- Divide and conquer · 12 tests
- Divide and conquer · 10 tests
- Divide and conquer · 8 tests
- Divide and conquer · 10 tests
- Divide and conquer · 10 tests
- Divide and conquer · 9 tests
- Divide and conquer · 9 tests
- Divide and conquer · 9 tests
- Randomization · 9 tests
- Randomization · 8 tests
- Randomization · 7 tests
- Randomization · 8 tests
- Randomization · 7 tests
- Randomization · 8 tests
- Randomization · 8 tests
- Randomization · 9 tests
- Randomization · 8 tests
- Randomization · 8 tests
- Randomization · 8 tests
- Randomization · 8 tests
- Randomization · 9 tests
- Randomization · 8 tests
- Greedy algorithms · 11 tests
- BFS on grids · 9 tests
- Backtracking · 16 tests
- Tree problems in depth · 14 tests
- DP: 1D · 10 tests
- Greedy algorithms · 10 tests
- DP: 1D · 10 tests
- Tree problems in depth · 10 tests
- Intervals · 10 tests
- Tries · 9 tests
- Heaps & priority queues · 13 tests