Number of Ways to Make Change

Given coin denominations and a target amount, return the number of unordered ways to make that amount using unlimited copies of each coin. This is the combinations version of the coin-change counting DP, and loop order is critical.

Input Format

coins = denominations, amount = target

Output Format

number of unordered ways to form the amount

Constraints

  • 1 <= coins.length <= 100; 1 <= coins[i] <= 1000; 0 <= amount <= 10^4

Examples

Example 1:

Input:

coins = [1,2,3]
amount = 4

Output:

4

Explanation:

The unordered combinations are 1+1+1+1, 1+1+2, 2+2, and 1+3.

Example 2:

Input:

coins = [2,5,3,6]
amount = 10

Output:

5

Explanation:

There are 5 unordered ways to make 10.

Loading...
Number of Ways to Make Change - Dp Knapsack