Back to problems Solve on LeetCode → See #198 House Robber →

Coin Change

LeetCode 322 • Medium • Dynamic Programming

Input: coins = [1, 2, 5], amount = 11  →  Output: 3
Min coins to make amount. dp[i] = min(dp[i-c]+1) for c in coins. dp[0]=0.

TimeO(amount × coins)nested loops
SpaceO(amount)dp array
Amount: 0 dp[amt]:
dp[i]
Current coin
Result
dp
Ready
Press Play. dp[amt] = min(dp[amt-c]+1) for c in coins. dp[0]=0, dp[i]=inf for i>0.