Coin Change II

Coin Change II: Counting Distinct Combinations

  • This problem involves finding the number of distinct combinations of coins that sum up to a given target amount.
  • It is a classic example of a Dynamic Programming (DP) problem, focusing on combinations rather than permutations.
Coin

Problem Description : Coin Change ||

You are given:

  1. An integer array coins where each element represents the denomination of a coin (e.g., 1, 5, 10, etc.).
  2. An integer amount representing the target sum.

Objective: Return the number of distinct combinations of coins that sum up to amount. If it’s impossible to reach the amount, return 0.

Problem Breakdown

  1. Input: 2D grid of non-negative integers.
  2. Objective: Find the length of the longest strictly increasing path.
  3. Movement: Can move to adjacent cells (up, down, left, right) but not diagonally.
  4. Constraints: Each move must go to a cell with a strictly greater value.
  5. Goal: Determine the longest path by efficiently exploring the grid.

Explanation:

  • 1+1+1+1 = 4
  • 1+1+2 = 4
  • 2+2 = 4
  • 1+3 = 4

Constraints: 

  • 1 <= coins[i] <= 1000
  • 1 <= coins.length <= 100
  • 0 <= amount <= 1000

There are mainly three approach to solve this problem – 

  1. Recursion
  2. Dynamic Programming (Top-Down)
  3. Dynamic Programming (Bottom-up)

1. Recursion

2. Dynamic Programming (Top-Down)

Time & Space Complexity
  • Time complexity: O(n^3)
  • Space complexity: O(n^2)

3. Dynamic Programming (Bottom-Up)

Time & Space Complexity
  • Time complexity: O(m∗n)
  • Space complexity: O(m∗n)

More Articles