โ† Trees, Graphs & DP
#9 most askedVery commonMedium1D DP

Coin Change

New to 1D DP? Learn it from scratch first
Dynamic Programming, Demystified โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Return the fewest coins needed to make amount, or -1 if it can't be made. You have unlimited coins of each value.

coin_change([1, 2, 5], 11) โ†’ 3 (5 + 5 + 1).

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def coin_change(coins, amount):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.