66. Combination Sum

candidates are distinct positive integers. Return every unique combination that sums to target. Each number may be used any number of times. Combinations are unique by their multiset; any order.

Example 1

Input: candidates = [2,3,6,7], target = 7
Output: [[2,2,3],[7]]

Example 2

Input: candidates = [2,3,5], target = 8
Output: [[2,2,2,2],[2,3,3],[3,5]]
Hint 1

Recurse with the same start index to allow reuse.

Hint 2

Only move forward in the list, so the same multiset is never produced twice.

Backtracking