Given a list of coin denominations and a target amount, implement a greedy algorithm to determine the minimum number of coins required to make the target amount. In this problem, you can assume the coin denominations form a canonical coin system (for example, US coins: [25, 10, 5, 1]). If the target amount cannot be made using the given coins, your function should return -1.
amount
.amount
is 0 or when no coins can be used.For coin denominations [1, 5, 10, 25]
and target amount 63
, the greedy algorithm would work as follows:
Total coins used = 2 (25-cent) + 1 (10-cent) + 3 (1-cent) = 6.
While a greedy strategy is optimal for canonical coin systems (like US coins), it may not work for arbitrary coin denominations. For this problem, you can assume that the coin set will allow a greedy solution to be optimal.
Happy coding on this November day!