216 Combination Sum III – Medium
Problem:
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Ensure that numbers within the set are sorted in ascending order.
Example 1:Input: k = 3, n = 7 Output:
Example 2:
Input: k = 3, n = 9
Output:
Thoughts:
This problem is modified based the Combination Sum II.
Difference is:
Candidates are numbers from 1 – 9 instead of given array.
Secondly, there is no constraints on number of elements in version II, but in III, the list of elements that adds up to given target value n has to have exact k elements.
Below is using an approach that’s modified based on the solution to Version II.
Solutions:
Last updated