Algorithms Playbook
← All problems
MediumSubsets & combinations →Similar to: Combination Sum

Ways to hit the target

Problem

Given an array of distinct positive integers candidates and a positive target, return all unique combinations whose numbers sum to target. The same number may be used any number of times. [2,3] and [3,2] count as the same combination.

Examples

Input: candidates = [2, 3, 6, 7], target = 7

Output: [2,2,3], [7]

Input: candidates = [2], target = 1

Output: (none)

Hints

    Try it first. Every hint reveals a bit more.

    Solution