256. Combination Sum III

Determine all possible set of k numbers that can be added together to equal n while meeting the following requirements:

  • There is only use of numerals 1 through 9.
  • A single use is made of each number.

Return list of every feasible combination that is allowed. The combinations can be returned in any order, but the list cannot have the same combination twice.

Example 1:

Input : k = 3 , n = 7

Output : [ [1, 2, 4] ]

Explanation :

1 + 2 + 4 = 7

There are no other valid combinations.

Example 2:

Input : k = 3, n = 9

Output : [[1, 2, 6],[1, 3, 5],[2, 3, 4]]

Explanation :

1 + 2 + 6 = 9

1 + 3 + 5 = 9

2 + 3 + 4 = 9

There are no other valid combinations.

Now Your Turn!

Pick the correct output for the given input

Input : k = 3, n = 8

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 2 <= k <= 9
  • 1 <= n <= 60

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
vector<vector<int> > combinationSum3(int k, int n) {
//your code goes here
}
};
Test Case

Input:

K
N