Combination Sum
Choose reusable candidates in nondecreasing order, prune sums above the target, and avoid duplicate combinations.
Core idea
Sort candidates and keep a start index so choices never decrease. Reusing the same index permits repeated values, while a negative remaining target prunes the branch.
Read the visualization
Each decision edge subtracts one candidate from the remainder. Green leaves reach zero, pruned nodes exceed the target, and backtracking restores the previous remainder.
Begin with an empty combination and the full remaining target.
Complexity and tradeoffs
Time: Exponential in target depth. Space: O(target/min candidate). Output size dominates, while sorted candidates permit early pruning and canonical ordering.
Where it fits
This pattern handles target sums, repeatable parts, and bounded construction. Changing the next start index switches between reusable and single-use candidates.