← Back to Data Structures & Algorithms
Question 551
Greedy Coins Used
Greedy Coins Used
Write greedy_coins_used(amount: int, coins: list[int]) -> list[int] that returns the list of coins a greedy cashier hands out: go through the coin values from largest to smallest (the starter orders them with sorted(coins)[::-1]) and, while the current coin still fits in remaining, append it to used and subtract it. The coins always include 1, so the amount is always reached. 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 list your function returns.
Expected Output:
[25, 25, 10, 5, 1, 1]= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Data Structures & Algorithms
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.