01 · Question
You are given an integer array coins and an integer amount. Return the fewest number of coins needed to make up that amount. If it is not possible, return -1.
02 · Analysis
Coin denominations are positive and may be reused; amount is nonnegative. dp[a] is the fewest coins for exact amount a. Try each coin no larger than a and use 1+dp[a-coin]; initialize dp[0]=0 and other states as impossible. Processing amounts upward makes every smaller amount ready. For m denominations and amount A, time O(Am), space O(A). Amount 0 needs 0 coins; an unreachable amount returns -1.