Coin Change Minimum

Hard
dynamic-programming Amazon Google Two Sigma

Given a list of coin denominations and a target amount, find the minimum number of coins needed. Return -1 if the amount cannot be made.

Example

coin_change([1, 5, 10, 25], 30)
# => 2  (25 + 5)
coin_change([2], 3)
# => -1

Test Cases

Python Editor

Output

Click "Run" to see results...