medium
Coin Change
Given coin denominations and a target amount, return the fewest coins needed to make exactly that amount, using any coin as often as you like. Return -1 if the amount cannot be formed.
Constraints
- 1 ≤ coins.length ≤ 12
- 1 ≤ coins[i] ≤ 2^31 - 1
- 0 ≤ amount ≤ 10^4
Examples
in: coins = [1,2,5], amount = 11
out: 3
5 + 5 + 1.
in: coins = [2], amount = 3
out: -1
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.