Intermediate
Open
Pro
Minimum Coin Combination
You are given an array of integers coins representing coin
denominations (in unlimited supply) and an integer amount.
Return the fewest number of coins needed to make up exactly
amount. If that amount cannot be made up by any combination of
the coins, return -1.
Example 1
Input: coins = [1, 3, 4], amount = 6
Output: 2
Explanation: 6 = 3 + 3, using 2 coins.
Example 2
Input: coins = [2], amount = 3
Output: -1
Explanation: 3 cannot be made using only coins of value 2.
Constraints
1 <= coins.length <= 121 <= coins[i] <= 2^31 - 10 <= amount <= 10^4
Share this question