Backtracking Practice Questions
Ten interview classics, every template represented. Each one is a direct instance of one of the four canonical shapes, advanced patterns, or constraint-satisfaction puzzles — once you spot the shape, the code writes itself.
Before reading any solution, force yourself through the five-question checklist:
- What’s the partial solution? (Usually
path+ an index.) - When is it complete? (Base case.)
- What are the candidate choices? (The loop body.)
- What’s the legality check? (Pruning — the highest-leverage optimization.)
- What’s the un-do? (The line after the recursive call.)
The code is a 10-line transcription of those five answers. If you can answer them, you’ve solved the problem.
Easy
| Problem | Pattern | Status |
|---|---|---|
| Subsets | The subset template | Available |
| Letter Combinations of a Phone Number | Fixed-depth, fixed-branching enumeration | Available |
| Generate Parentheses | Constraint-baked candidate generator | Available |
Medium
| Problem | Pattern | Status |
|---|---|---|
| Permutations | The permutation template + used[] array | Available |
| Combination Sum | Unbounded combinations with sort-and-prune | Available |
| Word Search | Grid DFS with in-place marking | Available |
| Palindrome Partitioning | String partition template | Available |
| Restore IP Addresses | Fixed-piece partition + validation | Available |
Hard
| Problem | Pattern | Status |
|---|---|---|
| N-Queens | Constraint placement + incremental column/diag state | Available |
| Sudoku Solver | 3-way constraint propagation (row/col/box) | Available |
More Practice (Coming Soon)
| Problem | Pattern | Status |
|---|---|---|
| Subsets II (with duplicates) | Subsets + duplicate-skip prune | Coming Soon |
| Permutations II (with duplicates) | Permutations + duplicate-skip prune | Coming Soon |
| Combination Sum II / III | Combinations + sum constraint | Coming Soon |
| Word Search II (trie + DFS) | Grid DFS over a Trie of words | Coming Soon |
| Word Break II | Partition + memoization | Coming Soon |
| Unique Paths III | Grid DFS visiting every walkable cell | Coming Soon |
| Partition to K Equal Sum Subsets | Bitmask DP / backtracking with pruning | Coming Soon |
| Expression Add Operators | Insert + - * between digits | Coming Soon |
| Beautiful Arrangement | Permutation with divisibility constraint | Coming Soon |
| Regular Expression Matching | Constraint matching with wildcards | Coming Soon |