โ† All coding problems

Fewest coins

HardDynamic programming

Given coin values coins (unlimited of each) and an amount, return the fewest coins that make the amount exactly, or -1 if it cannot be made. Amount 0 needs 0 coins.

Function
function solve(coins, amount)
Example 1
coins = [1,2,5]
amount = 11
โ†’ 3

Submit also runs 4 hidden tests, including edge cases.

console.log output is shown below