Backtracking
Try it, undo it, try the next thing: exhaustive search that cleans up after itself.
5 lessons · ~50 min · free
By the end you can
- See every generate-all-possibilities problem as a tree of choices
- Write the choose, explore, unchoose template and know why the undo matters
- Generate subsets, permutations, and combinations from one skeleton
- Prune branches early and feel the difference it makes
- Read constraint sizes to know when exponential search is the intended answer
Lessons
- 1Every choice is a branch9 minSubsets as include-or-exclude decisions, and the tree that every backtracking problem walks.
- 2Choose, explore, unchoose11 minThe three-beat template, and why forgetting the undo corrupts every path after the first.
- 3Permutations and combinations11 minOne skeleton, two bookkeeping choices: a used-set when order matters, a start index when it doesn't.
- 4Cutting branches early11 minCombination sum with sorting and early exits: the same tree, a fraction of the visits.
- 5Spotting backtracking problems8 min"All possible" cues, the constraint sizes that whisper exponential, and backtracking vs DP.
Practice it after
Real interview questions that test this pattern, in an editor with execution and AI feedback.