31 · Backtracking

#40 Combination Sum II

Mediumsolve on LeetCode ↗

frequently reported atMetaMicrosoftAmazonGoogle

the problem

In plain words

Candidates may contain duplicates; each index may be used at most once. Return all unique combinations that sum to target.

in candidates = [10,1,2,7,6,1,5], target = 8

out [[1,1,6],[1,2,5],[1,7],[2,6]]

in candidates = [2,5,2,1,2], target = 5

out [[1,2,2],[5]]

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

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #39
      Combination Sum
      Mediumin Backtracking
    2. #90
      Subsets II
      Mediumin Backtracking
    3. #416
      Partition Equal Subset Sum
      Mediumin Dynamic Programming