Medium · Dynamic Programming

Coin Change II

Given an integer amount and an array coins of distinct positive denominations, each usable any number of times, return the number of distinct combinations of coins (order ignored) that add up to exactly amount; amount 0 has exactly one combination, the empty one.

Examples

Example 1

{
  "coins": [1, 2, 5],
  "amount": 5
}

Output: 4 ways

Example 2

{
  "coins": [2],
  "amount": 3
}

Output: 0 ways

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Dynamic Programming problems