LeetCode 322 Coin Change - Solution

The core idea

Define dp[i] = minimum coins needed to make amount i.

For each amount i and each coin c, if c \le i, we can use coin c and then need dp[i - c] more coins.

dp[i] = 1 + min(dp[i - c] for each coin c where c \le i).

Base: dp[0] = 0 (zero coins for amount zero).

If dp[amount] stays at infinity, return 1-1.