You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0. You may assume that you have an infinite number of each kind of coin. The answer is guaranteed to fit into a signed 32-bit integer.
Example 1
Input: amount = 5, coins = [1,2,5]
Output: 4
Explanation: There are four ways to make 5: 5, 2 + 2 + 1, 2 + 1 + 1 + 1, and 1 + 1 + 1 + 1 + 1. Order does not matter, so 1 + 2 + 2 counts as the same as 2 + 2 + 1.
Example 2
Input: amount = 3, coins = [2]
Output: 0
Explanation: Only 2-coins are available, and they can only form even amounts, so 3 cannot be made. The answer is 0.
Example 3
Input: amount = 10, coins = [10]
Output: 1
Explanation: The single coin 10 makes 10 in exactly one way.
Process one coin denomination at a time, adding the ways it contributes to each amount. Putting coins on the outer loop counts each combination once (order-independent), avoiding double counting.
Run checks all cases above. Submit evaluates all test cases.