FunctionRacerProblemsRace

Fewest Banknotes

BeginnerGreedyPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems