Single-Use Combination Sum
List every unique combination that hits the target when each position can be used once and values may repeat.
The problem
Implement Solution.combinationSum2(candidates, target). Return every unique combination of candidates whose values add up to target. Each position in candidates can be used at most once, but candidates may contain equal values, and the same combination must not appear twice. For example, with candidates [10, 1, 2, 7, 6, 1, 5] and target 8, the answer is [1, 1, 6], [1, 2, 5], [1, 7] and [2, 6]. Return the combinations in any order. Constraints: 1 to 100 candidates, each value from 1 to 50, and target from 1 to 30. You may sort the input.
Starter code
class Solution:
def combinationSum2(self, candidates, target):
passPublic examples
candidates = [10, 1, 2, 7, 6, 1, 5], target = 8gives[[1, 1, 6], [1, 2, 5], [1, 7], [2, 6]]candidates = [2], target = 4gives[]candidates = [1, 2], target = 3gives[[1, 2]]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
