Money Sums
You have n coins with certain values. Your task is to find all possible distinct sums that can be created using any subset of the coins.
Example 1:
Input: n = 4 ,coins = [4,2,5,2]
Output: [2, 4, 5, 6, 7, 8, 9, 11, 13]
Explanation: Possible sums
- 2
- 4
- 5
- 2 + 4 = 6
- 2 + 5 = 7
- 4 + 2 + 2 = 8
- 4 + 5 = 9
- 4 + 5 + 2 = 11
- 4 + 5 + 2 + 2 = 13
Total distinct sums = 9.
Example 2:
Input: n = 3, coins = [2,3,7]
Output: [2, 3, 5, 7, 9, 12]
Explanation: Possible sums:
- 2
- 3
- 7
- 2 + 3 = 5
- 2 + 7 = 9
- 2 + 3 + 7 = 12
Now Your Turn!
Pick the correct output for the given inputInput: n = 2 , coins = [5,10]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 ≤ n ≤ 100
- 1 ≤ xi ​≤ 1000 (value of each coin)