Fewest Banknotes
A cashier pays out exactly amount dollars using banknotes worth 100, 50, 20, 10, 5 and 1 dollars, with as many of each kind as needed. Return the fewest banknotes that add up to amount. When amount is 0, return 0.
Example 1
amount 186
returns 6
186 = 100 + 50 + 20 + 10 + 5 + 1, one note of each kind, and no way uses fewer than 6.
Example 2
amount 40
returns 2
40 = 20 + 20 takes two notes; no single note is worth 40.
Constraints
0 <= amount <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Greedy problems
- Fewest JugsBeginner
- Greedy CoinsBeginner
- Least Total Waiting TimeBeginner
- Most Tasks in a Time BudgetBeginner
- Only the Best CountBeginner
- Shortest Walk to SeatsBeginner
- Stepping StonesBeginner
- Third One FreeBeginner