Skip to main content
PProfileMatch
← Path

Dynamic Programming · Classic DP Problems: Coin Change, Edit Distance and Knapsack

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Coin counter at the market

Trick to keep in mind+3 XP

Greedy grabs the biggest now; DP tries every coin at every amount.

Greedy never looks back, so one big early choice can leave an awkward remainder. With coins 1, 7 and 10 and a target of 14, taking 10 first needs four 1s, five coins in total, while 7 + 7 does it in two. Trying every coin per amount, as DP does, cannot be fooled this way.

Read it once, then a question tests whether the trick stuck.