Coin Change II
MediumDynamic Programming
Decode it first. Clues, constraints, pattern and plan before any code.You have unlimited coins of each value in coins. Return the number of combinations that add up to exactly amount. Order does not matter: 1 + 2 and 2 + 1 are the same combination. If no combination works, return 0.
amount = 5, coins = [1, 2, 5] → 4 (5, 2+2+1, 2+1+1+1, 1+1+1+1+1)
amount = 3, coins = [2] → 0
amount = 10, coins = [10] → 1Constraints
1 <= coins.length <= 3001 <= coins[i] <= 5000- All values in
coinsare unique. 0 <= amount <= 5000- The answer fits in a 32-bit signed integer.