Combination sum

Write codeMedium22 min

Your task

Given a list of distinct positive integers and a target, return all unique combinations where the chosen numbers sum to target. The same number may be used unlimited times. Each combination must be sorted ascending and the overall list sorted. 1 <= len(candidates) <= 8, target <= 30.

Examples

combination_sum(candidates: list[int], target: int) -> list[list[int]]
Example 1
Inputcombination_sum([2, 3, 6, 7], 7)
Output[[2, 2, 3], [7]]