Back to DSA

Combination Sum

medium
Acceptance: 51%
BacktrackingArrays

Given an array of distinct positive integers (candidates) and a target sum, find all unique combinations of candidates that add up to the target. Each candidate may be used an unlimited number of times. Two combinations are different if they differ in the frequency of at least one chosen number.

Examples

Example 1:
Input:candidates = [3,5,7], target = 10
Output:[[3,7],[5,5]]
Example 2:
Input:candidates = [2,4,6], target = 8
Output:[[2,2,2,2],[2,2,4],[2,6],[4,4]]

Hints

00:00
1234567