Write a method named subsetSums
that uses dynamic programming to find the number of sub-lists of an array that have a given sum.
Your method accepts an array of integers and a target value k as parameters and returns the number of sub-lists that sum to exactly k.
For example, if the array stores {9, 4, 20, 10, 3, 5}
and k is 33
, the sub-lists of {9, 4, 20}
and {20, 3, 10}
add to that sum, so you should return 2
.
The key constraint of this problem is that you must solve it using a bottom-up dynamic programming approach.
Do not use recursion. Your solution must use dynamic programming instead.
You are allowed to construct any data structures (array, list, set, map, etc.) necessary to store the data for your dynamic programming algorithm.
Note: It is possible to solve this problem in O(N) time where N is the number of elements in the array.