Combination Sum

Medium
ArrayBacktrackingAmazonMicrosoft
Given distinct positive candidate numbers and a target, print all unique combinations where chosen numbers sum to the target. Each candidate may be used any number of times. Input format: - First line: n target - Second line: n distinct positive integers Print each combination in nondecreasing order, one combination per line. Print combinations in lexicographic order. Print `EMPTY` if there are none.

Constraints

1 <= n <= 30
1 <= candidates[i], target <= 500

Sample tests

Sample 1

Sample 2

Sign in to submit