15. Recursion & Backtracking

Subsets, permutations, combinations, N-Queens, Sudoku and word search.

🎬 Episodes 29–36: video coming soon
Your progress0 of 18
2easy
13medium
3hard

Understand the topic

Recursion means solving a problem using a smaller copy of itself, plus a base case that stops the calls. Each call waits on the call stack until the smaller call returns.

Backtracking is recursion that builds an answer one choice at a time. The template is: choose, explore (recurse), un-choose. Subsets, permutations, combinations, N-Queens and Sudoku all use this same template. Only three things change between problems: the choices at each step, when a path is complete, and when to prune a dead branch early.

#ProblemPatternLevel
1 Fibonacci Number #509 Recursion → iteration Easy LeetCode ↗
2 Sum of All Subset XOR Totals #1863 Pick / not pick recursion Easy LeetCode ↗
3 Subsets #78 Backtracking (pick / not pick) Medium LeetCode ↗
4 Subsets II #90 Backtracking with duplicate skip Medium LeetCode ↗
5 Permutations #46 Backtracking with used[] Medium LeetCode ↗
6 Permutations II #47 Backtracking with duplicate skip Medium LeetCode ↗
7 Combinations #77 Backtracking with pruning Medium LeetCode ↗
8 Combination Sum #39 Backtracking with reuse Medium LeetCode ↗
9 Combination Sum II #40 Backtracking, use once, skip duplicates Medium LeetCode ↗
10 Letter Combinations of a Phone Number #17 Backtracking over choices Medium LeetCode ↗
11 Generate Parentheses #22 Backtracking with counts Medium LeetCode ↗
12 Palindrome Partitioning #131 Backtracking on cut positions Medium LeetCode ↗
13 Word Search #79 Grid DFS backtracking Medium LeetCode ↗
14 Partition to K Equal Sum Subsets #698 Backtracking with pruning Medium LeetCode ↗
15 Path with Maximum Gold #1219 Grid DFS backtracking Medium LeetCode ↗
16 N-Queens #51 Backtracking row by row Hard LeetCode ↗
17 Sudoku Solver #37 Backtracking on empty cells Hard LeetCode ↗
18 Permutation Sequence #60 Factorial number system Hard LeetCode ↗

Work top to bottom — each list goes from easy to hard. Try a problem for at least 15 minutes before opening a hint. Ticks are saved in your browser.