FreeCareerPath
Build the PrimitiveMedium

Coin Change

Write `coin_change(coins, amount)` returning the fewest coins summing to the amount, or `-1` if impossible. Coins may be reused freely. coin_change([1,2,5], 11) -> 3 (5 + 5 + 1) Greedy — always take the largest coin — is wrong: with coins [1, 3, 4] and amount 6, greedy gives 4+1+1 = 3 coins where 3+3 = 2 is optimal. Build up an array where each entry is the best for that amount, and be ready with that counterexample.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Coin Change" are saved to your account — logging in takes a few seconds.

Coin Change — FreeCareerPath