Skip to content
Preptima
mediumCodingEntryMidSenior

Given a set of coin denominations and a target amount, return the fewest coins that make it exactly. Why would you not just take the largest coin first each time?

4 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Largest-coin-first fails on denominations like 1, 3 and 4, so you fill a table where entry i is the fewest coins making amount i and each entry takes the best over all denominations.

Was this answer helpful?

Likely follow-ups

  • Count the distinct combinations that make the amount instead of minimising coins. Which loop has to go on the outside?
  • Each coin may be used at most once. What changes about the direction of the inner loop?
  • Return the actual multiset of coins, not just how many.
  • The amount is a billion and there are three denominations. Is this table still the right tool?

Related questions

Related Topics