CJCoding With Joseph
15free / daySign inCreate account

Greedy Coins

Write greedy_coins(amount: int, coins: list[int]) -> int that returns how many coins a greedy cashier uses: order the coin values from largest to smallest with sorted(coins)[::-1] and, for each coin, keep subtracting it from the amount still owed while it fits, counting one coin each time. The coins always include 1. Greedy is fast but not always optimal: with coins 25 10 1 and an amount of 30 it uses six coins (25 and five 1s) where three 10s would do; just report what greedy does. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, the amount and then the space-separated coin values; the tests print the count your function returns.

Expected Output:

6

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
67\n25 10 5 1\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.