Combination Sum, traced one call at a time

Each box is one call to backtrack, labelled with the numbers chosen so far and how much is still remaining. A child may reuse the same number (it passes i, not i+1). Red ✂ boxes show where break cuts the search because a number is already too big.

solution
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Recursion tree

Hover a combination in res to find its call

not called yet running now paused, waiting on a child remaining hit 0 (saved) finished, no match pruned by break

Call stack

Top frame runs; the rest are paused

Variables

candidates dim = before start, red = bigger than remaining

target = sum(path) + remaining

0

path one shared list, edited in place by every call

res

Time and space complexity

t = target, m = smallest candidate, n = number of candidates. The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Use up to 6 distinct positive candidates and a target up to 30; very large trees are rejected so the picture stays readable.