Combination Sum

Medium Solved

Description

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

The same number may be chosen from candidates an unlimited number of times.

Input format:

  • Line 1: JSON array of integers (candidates)
  • Line 2: Integer target

Example

Input:
[2,3,6,7]
7

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

Note:

Print the result as a JSON array of arrays. Order does not matter.

No submissions yet.

Discuss backtracking, recursion depth, pruning, and complexity.

Test Cases