Backtracking
This is a premium interview-preparation course built around one template that solves a whole family of problems: **choose, explore, unchoose**. Backtracking is depth-first search over a decision tree — at each node you make a choice, recurse to explore its consequences, then undo the choice so the next branch starts clean. The art is not the recursion itself but knowing **what a state is**, **how choices branch**, and **when to prune** so an exponential space stays tractable. You will start with the mental model (decision trees, state-space search, the recursion tree, and how to reason about complexity), then work through curated problems grouped by the patterns interviewers actually test: subsets, permutations, combinations, string partitioning, board search, and advanced pruning. Every lesson recognises the pattern first, draws the recursion tree, explains the pruning, then shows a clean Java 17 implementation.
25
Curated lessons
7
Learning modules
7h 14m
Est. study time
9
Target companies
What you'll learn
- Recognise the backtracking signal: build every valid configuration by making and undoing sequential choices.
- Model state, choices, and the base case so the choose/explore/unchoose template writes itself.
- Prune aggressively — sort-and-skip duplicates, bound checks, and early termination — to tame the search tree.
- Reason about the size of the decision tree to state honest time and space complexity.
Your progress
0 / 25
problems completed
25 available now · keep going!
Mark lessons complete as you work through them. Progress is saved on this device and syncs to your account when you sign in.
Learning roadmap
Work top to bottom — each module builds on the last.
- 1
Backtracking Fundamentals
DFS over choices: choose, explore, unchooseThe mental model: a decision tree over a state space, the choose/explore/unchoose template, pruning, and how to reason about the recursion tree's size.
8/8 problems1h 1m - 2
Subset Pattern
Take / skip each index; sort-skip duplicatesInclude-or-exclude each element to enumerate the power set, then learn the sort-and-skip trick that removes duplicate subsets.
2/2 problems34m - 3
Permutation Pattern
Fix each position with an unused elementOrder matters: place every unused element at each position, and prune duplicate permutations with a used-array plus sorted skip.
2/2 problems38m - 4
Combination Pattern
Start-index recursion; bound and skipChoose k of n without regard to order using a start index, then add target sums, reuse rules, and duplicate skipping.
4/4 problems1h 16m - 5
String Backtracking
Choose a prefix / cut point, recurse on the restPartition and map strings: expand phone digits, cut a string into palindromes, and place dots to form valid IP addresses.
3/3 problems58m - 6
Board Search
Place, validate, recurse, undo the cellSearch a grid with constraints: walk a word through a matrix, place non-attacking queens, and solve Sudoku with constraint propagation.
3/3 problems1h 25m - 7
Advanced Backtracking
Aggressive pruning over a wide decision treeHarder search spaces where pruning is the whole game: inject operators between digits, fill buckets to equal sums, and split into descending values.
3/3 problems1h 22m
Modules
7 themed modules from fundamentals to advanced.
Backtracking Fundamentals
The mental model: a decision tree over a state space, the choose/explore/unchoose template, pruning, and how to reason about the recursion tree's size.
Subset Pattern
Include-or-exclude each element to enumerate the power set, then learn the sort-and-skip trick that removes duplicate subsets.
Permutation Pattern
Order matters: place every unused element at each position, and prune duplicate permutations with a used-array plus sorted skip.
Combination Pattern
Choose k of n without regard to order using a start index, then add target sums, reuse rules, and duplicate skipping.
String Backtracking
Partition and map strings: expand phone digits, cut a string into palindromes, and place dots to form valid IP addresses.
Board Search
Search a grid with constraints: walk a word through a matrix, place non-attacking queens, and solve Sudoku with constraint propagation.
Advanced Backtracking
Harder search spaces where pruning is the whole game: inject operators between digits, fill buckets to equal sums, and split into descending values.
Full curriculum
17 problems and 8 concept lessons in learning order.
- 1What is BacktrackingBacktracking Fundamentals Concept
- 2The Decision TreeBacktracking Fundamentals Concept
- 3State Space SearchBacktracking Fundamentals Concept
- 4Choose, Explore, UnchooseBacktracking Fundamentals Concept
- 5Pruning the SearchBacktracking Fundamentals Concept
- 6The Recursion TreeBacktracking Fundamentals Concept
- 7Time Complexity of BacktrackingBacktracking Fundamentals Concept
- 8When to Use BacktrackingBacktracking Fundamentals Concept
- 9SubsetsSubset PatternMedium
- 10Subsets IISubset PatternMedium
- 11PermutationsPermutation PatternMedium
- 12Permutations IIPermutation PatternMedium
- 13CombinationsCombination PatternMedium
- 14Combination SumCombination PatternMedium
- 15Combination Sum IICombination PatternMedium
- 16Combination Sum IIICombination PatternMedium
- 17Letter Combinations of a Phone NumberString BacktrackingMedium
- 18Palindrome PartitioningString BacktrackingMedium
- 19Restore IP AddressesString BacktrackingMedium
- 20Word SearchBoard SearchMedium
- 21N-QueensBoard SearchHard
- 22Sudoku SolverBoard SearchHard
- 23Expression Add OperatorsAdvanced BacktrackingHard
- 24Matchsticks to SquareAdvanced BacktrackingMedium
- 25Splitting a String Into Descending Consecutive ValuesAdvanced BacktrackingMedium