Proficient Level
Implement the method coinChangeMinCoins that returns the minimum number of coins needed for an amount.
You may use each coin value any number of times. Return the fewest coins needed to make the target amount exactly.
The task is designed to test careful handling of edge cases, not only the most common input.
- Use only the first
sizecoin values. - Return
0when the amount is0. - Return
-1when the amount cannot be formed.
Use dynamic programming where dp[x] stores the fewest coins needed for amount x.