Close
Topic list
Combination Sum III
MEDIUM
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Combination Sum III

Contributed by
Medium
0/80
Share

## Problem Statement

#### Example:

``````Input: ‘K’ = 2, ‘N’ = ‘5’

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

1 + 4 = 5 and 2 + 3 = 5. Only these two combinations are there which sum upto n so answer is [[1, 4], [2, 3]].
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
2
5
3
8
``````
##### Sample Output 1 :
``````1 4
2 3
1 2 5
1 3 4
``````
##### Explanation Of Sample Input 1 :
``````For the first case:
1 + 4 = 5 and 2 + 3 = 5. Only these two combinations are there which sum upto n so answer is [[1, 4], [2, 3]].

For the second case:
1 + 2 + 5 = 8 and 1 + 3 + 4 = 8. Only these two combinations are there which sum upto n so answer is [[1, 2, 5], [1, 3, 4]].
``````
##### Sample Input 2 :
``````2
4
10
3
9
``````
##### Sample Output 2 :
``````1 2 3 4
1 2 6
1 3 5
2 3 4
``````
Auto
Console