You are given an integer array coins representing coins of different denominations and an integer amount. Return the fewest number of coins to make that amount. If impossible, return -1. You may use each coin infinite times.
coins = [1,2,5], amount = 113coins = [2], amount = 3-1Unbounded knapsack: each coin can be used multiple times. For each target amount a, we try every coin c that fits. If we use coin c, we need 1 + min coins for a−c, so candidate = dp[a−c] + 1. We keep the minimum. dp[0]=0 is the base case.