Back to DSA
Coin Change
mediumYou have coins of various denominations available in unlimited supply. Determine the minimum number of coins required to reach a specified total. If the total cannot be assembled from the given denominations, return -1.
Examples
Example 1:
Input:
coins = [1,3,4], amount = 6Output:
2Explanation: 6 = 3 + 3, using two coins.
Example 2:
Input:
coins = [5,7], amount = 3Output:
-1Explanation: No combination of 5s and 7s can produce 3.
Hints
1234567