You are given a list of coin denominations and a target amount of money. You may use each denomination any number of times.
Return the fewest number of coins needed to make up the target amount exactly. If no combination of the given coins sums to the amount, return -1.
Example 1
Input: coins = [1, 2, 5], amount = 11
Output: 3
The amount 11 can be formed as 5 + 5 + 1, which uses three coins and no smaller count is possible.
Example 2
Input: coins = [2], amount = 3
Output: -1
With only the denomination 2 available, the odd amount 3 can never be reached, so the answer is -1.
Constraints
1 <= coins.length <= 121 <= coins[i] <= 2^31 - 10 <= amount <= 10^4See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI