week 8 of 15
Backtracking
Get comfortable with these coding mechanics first: building a path list, choose then explore then undo, copying the path when you save it, passing a start index. Template to type from memory by the end of the week: backtrack(state): if complete, save a copy. For each choice: add it, recurse, remove it.
- 66Subsets (opens LeetCode in a new tab)Include or skip with a start indexMedium
- Common mistake
- Saving path itself instead of a copy.
- 67Letter Combinations of a Phone Number (opens LeetCode in a new tab)Backtracking over positionsMedium
- Common mistake
- Empty input should return an empty list.
- 68Combination Sum (opens LeetCode in a new tab)Backtracking with reuseMedium
- Common mistake
- Using i+1 and blocking reuse.
- 69Permutations (opens LeetCode in a new tab)Used arrayMedium
- Common mistake
- Forgetting to unmark after returning.
- 70Generate Parentheses (opens LeetCode in a new tab)Backtracking with countsMedium
- Common mistake
- Checking the string instead of the counts.
- 71Combination Sum II (opens LeetCode in a new tab)Sort and skip duplicatesMedium
- Common mistake
- Skipping when i > 0 instead of i > start.
- 72Palindrome Partitioning (opens LeetCode in a new tab)Backtracking + palindrome checkMedium
- Common mistake
- Getting the slice bounds wrong (end is inclusive in this loop).
- 73Word Search (opens LeetCode in a new tab)Grid DFS with backtrackingMedium
- Common mistake
- Restoring the cell on every exit path.
- 74N-Queens (opens LeetCode in a new tab)Constraint backtracking (hard)Hard
- Common mistake
- Getting the diagonal formulas wrong. Use r - c and r + c.