Reusable combination sum
Return all nondecreasing combinations of unique positive candidates summing to nonnegative target, in lexicographic order. A candidate may be reused.
path, remaining, choice = [2], 5, 2
print(path+[choice], remaining-choice)Reason about the state
Sort candidates and carry a minimum candidate index through recursion. Reusing the same index permits repetition while excluding permutations of one combination. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return all nondecreasing combinations of unique positive candidates summing to nonnegative target, in lexicographic order. A candidate may be reused.
The explanation opens here once every check passes.