39. Combination Sum

Practice Combination Sum for free on NudgeCode: Medium, Backtracking pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

candidates holds distinct positive integers. Return every distinct combination of them that sums to target, where each candidate may be used any number of times. Two combinations are the same if they use the same numbers the same number of times. The combinations, and the numbers inside each, can be in any order.

Example

candidates = [2,3,6,7], target = 7  ->  [[2,2,3],[7]]

Constraints