K Sum Unique Combinations
Given a list of integers, write a program to print the count of all possible unique combinations of numbers whose sum is equal to K.
Input
The first line of input will contain space-separated integers.
The second line of input will contain an integer, denoting K.
Output
The output should be containing the count of all unique combinations of numbers whose sum is equal to K
All possible unique combinations of the given list are
(6,) (2,) (4,) (1,) (3,)
(2, 4) (1, 2) (3, 4) (4, 6) (1, 4) (2, 3) (2, 6) (3, 6) (1, 6) (1, 3)
(3, 4, 6) (2, 3, 6) (1, 2, 6) (1, 2, 3) (1, 4, 6) (1, 3, 4) (2, 3, 4) (1, 3, 6) (2, 4, 6) (1, 2, 4)
(2, 3, 4, 6) (1, 2, 3, 4) (1, 2, 4, 6) (1, 2, 3, 6) (1, 3, 4, 6)
(1, 2, 3, 4, 6)
-1 4 5 6 7 8 2 4 5 2 3 8
7
The unique combinations with the sum equal to 7 are
7
-1 8
3 4
2 5
-1 3 5
-1 4 4
-1 2 6
2 2 3
-1 2 2 4
Sample Input 1
2 4 6 1 3
6
Sample Output 1
3
Sample Input 2
-1 4 5 6 7 8 2 4 5 2 3 8
7
Sample Output 2
9
Comments
Leave a comment