Fewest Coins With A Table
Fewest Coins With A Table
Write count_min_coins_dp(amount: int, coins: list[int]) -> int that returns the fewest coins that make amount exactly, or -1 when it cannot be made, using a table instead of greed: best[t] holds the fewest coins for the total t. Build best with an impossible value in every entry (amount + 1 works; call it big) and then set best[0] to 0; loop total over range(1, amount + 1) and, for every coin that fits, let best[total] become best[total - coin] + 1 when that is smaller. The answer is best[amount], or -1 if it still holds the impossible value. This fixes the greedy failure: 30 with coins 25 10 1 is 3 coins. 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:
3= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...