← Practice · Dynamic programming
Coin Change Medium
Given coin denominations and a target amount, return the fewest coins needed to make exactly that amount, or -1 if impossible. You have unlimited coins of each denomination.
Examples
coins = [1,2,5], amount = 11 -> 3 (5+5+1)coins = [2], amount = 3 -> -1
Define a function named coinChange in JavaScript.
00:00▶ Visualize
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests