Lesson 20 — Coin change (DP)
Dynamic programming: small answers build big ones
Dynamic programming (DP) solves a big problem by first solving all the small versions and storing them in a table. For "fewest coins to make an amount", dp[a] = fewest coins for amount a. To fill dp[a], try every coin c: use one c, plus the best way to make a − c, which you already know.
best[t] = min(best[t], best[t - step] + 1) # use one more step of this size
float("inf") (infinity) means "not possible yet".
Why it matters: DP solves route planning, text diffing and spell-check suggestions that brute force could never finish.
Write the dp update line. Expected: 3 (5 + 5 + 1), then 2 (3 + 3).
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Algorithms Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Algorithms Foundations books — check the publication year so the examples match current versions.
Search Amazon →