LeetCode 39 Combination Sum - Solution

The core idea

Backtrack, but allow reusing the same candidate. Track the remaining target.

At each step, try adding candidates (starting from current index to avoid duplicates like [2,3] and [3,2]). If remaining becomes 0, found a valid combination. If remaining goes negative, stop exploring.

Starting from the current index ensures combinations are built in sorted order, avoiding duplicates.