Combination Sum II

Given a collection of candidate numbers candidates and a target number target, return all unique combinations in candidates where the candidate numbers sum to target.

Each number in candidates may be used at most once in each combination.

The solution set must not contain duplicate combinations. You may return the combinations in any order.

Example 1
Inputcandidates = [10,1,2,7,6,1,5], target = 8
Output[[1,1,6],[1,2,5],[1,7],[2,6]]
The unique combinations that sum to 8 are [1, 1, 6], [1, 2, 5], [1, 7], and [2, 6].
Example 2
Inputcandidates = [2,5,2,1,2], target = 5
Output[[1,2,2],[5]]
The unique combinations that sum to 5 are [1, 2, 2] and [5].

Constraints

  • 1 <= candidates.length <= 100
  • 1 <= candidates[i] <= 50
  • 1 <= target <= 30

Asked at 17 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate