Combination Sum
Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target.

30:00

Combination Sum
medium
Topics
Companies

Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target.

Example 1:
Input: {"candidates":[2,3,6,7],"target":7}
Output: [[2,2,3],[7]]
Constraints:
  • 1candidates.length301 \leq \text{candidates.length} \leq 30

  • 2candidates[i]402 \leq \text{candidates}[i] \leq 40

  • All elements of candidates are distinct.

  • 1target401 \leq \text{target} \leq 40

Input
arr ={"candidates":[2,3,6,7],"target":7}

Check sum: 0 vs target 7

Candidates

2

3

6

7

Current Combination

Empty

Sum: 0
Found Solutions
Variables
VariableValue
i0
total0
cur[]
DepthFunction Call
1dfsi=0, cur=[], total=0
0/136