Gamified challenge · Unbounded knapsack DP
coins lists the coin values the machine holds, and it has an unlimited supply of each. It must pay out exactly amount.
Write minCoins(coins, amount) (Python: min_coins) that returns the fewest coins that add up to amount, or -1 if no combination does. For coins = [1, 3, 4] and amount = 6 the answer is 2 (3 + 3), even though grabbing the biggest coin first gives 4 + 1 + 1.
Coins are positive and may come in any order. amount is between 0 and 200, and paying 0 takes 0 coins.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google