Loading repovive.com/problems/classics/52
Given coin values and a target sum, find the minimum number of coins needed to form the target. Each coin value may be used any number of times.
3 6 1 3 4
The target 6 is reached with 3 + 3, using two coins. No one-coin choice has value 6.
2
2 7 4 6
Using coins of value 4 and 6 cannot make the odd target 7, so the answer is -1.
-1
4 0 2 5 7 11
The target is already 0, so the empty choice uses 0 coins.
0