You are given an array coins of coin values and a target amount. You have an unlimited supply of every coin.
Return the fewest coins that add up to exactly amount. If no combination of coins adds up to amount, return -1.
Examples
Example 1
Input: coins = [1,2,5], amount = 11
Output: 3
11 = 5 + 5 + 1.
Example 2
Input: coins = [2], amount = 3
Output: -1
Any number of 2s adds up to an even total, so 3 can't be made.
Example 3
Input: coins = [1], amount = 0
Output: 0
An amount of 0 needs no coins at all.
Example 4
Input: coins = [1,3,4], amount = 6
Output: 2
6 = 3 + 3. Taking the biggest coin first gives 4 + 1 + 1, which is one coin too many.
Example 5
Input: coins = [7,5], amount = 24
Output: 4
24 = 7 + 7 + 5 + 5. Taking the biggest coin first uses three 7s, reaches 21, and then gets stuck with 3 left, even though the amount can be made.
Constraints
1 <= coins.length <= 121 <= coins[i] <= 2^31 - 10 <= amount <= 10^4