Problem
You get two integers k and n. Find all sets of k different numbers that add up to n. You can use only the numbers 1 to 9.
Return a list of all such sets. Each set is a list of numbers. The list must not contain the same set two times.
You can return the sets in any order. The numbers inside each set can also be in any order.
Example 1
- Input:
- k = 2, n = 5
- Output:
- [[1,4],[2,3]]
- Explanation:
1 + 4 = 5and2 + 3 = 5. You cannot use[5], because each set must have 2 numbers.
Example 2
- Input:
- k = 3, n = 10
- Output:
- [[1,2,7],[1,3,6],[1,4,5],[2,3,5]]
Example 3
- Input:
- k = 2, n = 1
- Output:
- []
- Explanation:
- The smallest sum of 2 different numbers is
1 + 2 = 3. So no set has the sum 1.
Constraints
- 2 <= k <= 9
- 1 <= n <= 60
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Combination Sum
Coding
- Combination Sum II
Coding
- Combination Sum IV
Coding
- Path Sum III
Coding · Binary Tree · Depth-First Search · Tree
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 216. Combination Sum III
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source