Pattern 06 of 08 · backtracking
Backtracking & Decision Trees
Construct candidates incrementally and systematically abandon ('backtrack') paths as soon as they fail to satisfy problem constraints.
- Builds on
- Tree BFS & DFS
- Unlocks
- 1D Dynamic Programming
See the invariant
Step through itbacktrackingInteractive Sandbox
Curated visualizer for backtracking is available via Socratic AI Mentor steps and the interactive playground below.
Pattern InvariantTwo Pointers
Converging search on sorted array: Target Sum = 26
Step 1 of 3
L
2
[0]7
[1]11
[2]15
[3]19
[4]R
23
[5]nums[0] (2)+nums[5] (23)=25<Target (26)
Sum 25 < target (26). Since array is sorted, we MUST increase left pointer (L: 0 to 1) to seek a larger sum.
Speed: