Number of Sums of a Subset
You are given an array of integers and an integer K as arguments. Return the number of different ways that a subset of integers can add up to K. If no solution exists, returns 0.
The argument array will contain no duplicated integers.
Requirements
- Must return an integer
Example #1
solve([1,2,3,4,5],8)
> 3
We can arrive at 8 by the following: (3 + 5 = 8), (4+ 3 + 1 = 8), and (1 + 2 + 5 = 8) so we return 3
Example #2
solve([10,20,3,4,5],1)
> 0
There are no combinations of numbers that can be added to reach 1, so we return 0.