Combination sum, each number once
Write combos_once(candidates, target) that returns every distinct combination of numbers
from candidates (which may contain repeats) that sums to target, using each position
at most once. Each combination is in non-decreasing order and no combination appears twice.
Order of the output does not matter.
combos_once([10, 1, 2, 7, 6, 1, 5], 8) -> [[1, 1, 6], [1, 2, 5], [1, 7], [2, 6]]
combos_once([2, 5, 2, 1, 2], 5) -> [[1, 2, 2], [5]]
The point is to practise combining the start + 1 rule (no reuse) with the duplicate
skip at the same level.
def combos_once(candidates, target):
...