Combination Sum
Find all combinations that sum to a target, with unlimited reuse of candidates.
Pattern fit
This is the backtracking pattern where the recursion keeps an index to avoid duplicate ordering while still allowing the current value to be reused.
Key observation
The same index can be chosen again because repetition is allowed, but earlier indices should not be revisited after moving forward.
Target complexity
Exponential / O(target)
How to break down the solution cleanly
This is the backtracking pattern where the recursion keeps an index to avoid duplicate ordering while still allowing the current value to be reused.
The same index can be chosen again because repetition is allowed, but earlier indices should not be revisited after moving forward.
Model the decision tree explicitly.
Choose the next candidate set for the current depth.
Reference implementation
Python# Generic pattern template
def backtrack(path):
if complete(path):
answer.append(path[:])
return
for choice in choices(path):
if not valid(choice, path):
continue
path.append(choice)
backtrack(path)
path.pop()
Common pitfalls
Incrementing the start index even when reuse is allowed.
Failing to stop when the remaining target becomes negative.
Common follow-ups
How does Combination Sum II differ?
Why is sorting useful for pruning here?
Continue with related problems
Build repeatable depth inside the Backtracking cluster before moving on.