17/28
Part 5 of 7 · What it costsLearn and do
What it costs
Time is amount times coins, with the amount in cents
The practice problem's $500 test is 50,000 cents. With six coins, min_coins takes 300,000 inner steps: 6 coins at each of 50,000 amounts. count_ways takes 299,365, because each coin's pass starts at its own value. That runs in a few hundredths of a second, well under the test's 2-second limit.
In general, write for the amount in cents and for the number of distinct coins. Both functions visit amounts and try coins at each:
The unit is part of the answer.
Space is one row of cells. The counting table drawn with one row per coin would be cells, and the flat list keeps a single row. Rebuilding the coins adds one more row of .
One more digit makes the table ten times longer
A table in cents for $1,000,000. How many cells?
Pick an answer above to see the rest