Skip to content
DSA Visualizerpreview

Coin change (fewest coins)

Fewest coins for every amount from 0 up: each amount is one coin more than some smaller amount.

O(amount × coins) time · O(amount) space

Coins1, 3, 4make 6

Coins 1, 3, 4. dp[a] = fewest coins that make a. Zero coins make 0; everything else starts at ∞.

View
Fewest coins for amounts 0 to 6: 0, ∞, ∞, ∞, ∞, ∞, ∞.

Fewest coins for amounts 0 to 6: 0, ∞, ∞, ∞, ∞, ∞, ∞.

  • compare
  • swap or write
  • settled

1 / 15

Speed

Space play · ← → step · Home End jump · drag the strip to scrub