ReviseAlgo Logo
MediumVery High Frequency30 min

Backtracking Fundamentals

The choose-explore-unchoose mental model, decision trees, and pruning strategies.

Backtracking = try a choice, recurse, undo the choice. Build solution incrementally, abandon partial solutions that can't work. Template: choose → explore → unchoose.

Backtracking

Backtracking Pattern

Combination Sum

O(n^(t/m))t = target, m = min coin. Each element reusable (unbounded). Use start index to avoid duplicates.
Step-by-step1 / 5
marker
2
0
marker
3
1
marker
6
2
marker
7
3

target=7. Start DFS with []

Try each candidate as first element. path=[], remain=7.