WORLD 4
BACKTRACKING
Try a choice, explore everything after it, then undo it and try the next: every subset, every order, every sum.
STAGE 0 Backtracking tutorial
0:00 / 0:00
The move
Build an answer one choice at a time and undo the choices that lead nowhere. Three beats: choose (add a candidate), explore (recurse), un-choose (pop it so the next choice starts clean). Prune early when a partial answer can't work.
- Spot it
- The problem asks for all, every or generate, with combinations, permutations, subsets or placements, and the input is small.
- Cost
- Exponential: it visits every candidate, such as 2^n subsets or n! orders, so inputs stay small.
20 STAGES
☆☆☆☆☆ Clear any 5 stages to beat this world, or all 20 for 100%.
MEDIUM2:09Subsets
BacktrackingLC 78▶ START
MEDIUM2:00Subsets II
BacktrackingLC 90▶ START
MEDIUM2:10Combinations
BacktrackingLC 77▶ START
MEDIUM2:09Generate Parentheses
BacktrackingLC 22▶ START
MEDIUM2:10Letter Combinations
BacktrackingLC 17▶ START
MEDIUM2:06Permutations
BacktrackingLC 46▶ START
MEDIUM2:09Permutations II
BacktrackingLC 47▶ START
MEDIUM2:03Combination Sum
BacktrackingLC 39▶ START
MEDIUM2:11Combination Sum II
BacktrackingLC 40▶ START
MEDIUM2:04Combination Sum III
BacktrackingLC 216▶ START
MEDIUM2:01Target Sum
BacktrackingLC 494▶ START
MEDIUM2:09Partition to K Equal Sum Subsets
BacktrackingLC 698▶ START
MEDIUM2:10Matchsticks to Square
BacktrackingLC 473▶ START
MEDIUM2:07Palindrome Partitioning
BacktrackingLC 131▶ START
MEDIUM2:11Restore IP Addresses
BacktrackingLC 93▶ START
MEDIUM2:02Word Search
BacktrackingLC 79▶ START
HARD2:04Word Search II
Trie + backtrackingLC 212▶ START
HARD2:03N-Queens
BacktrackingLC 51▶ START
HARD2:07N-Queens II
BacktrackingLC 52▶ START
HARD2:06Sudoku Solver
BacktrackingLC 37▶ START