Wednesday 5 October 2022

Data Structures and Algorithms - Problem - 3 Coin Change challenge 2

In the previous coin challenge, We solved the problem where have an integer array of coins of different denominations and an integer amount representing an amount of money.  and have an infinite number of each coin, and the order of coins doesn't matter, What we need to return is the fewest number of coins that we need to make up that amount.

In this blog, We are going to see another famous coin challenge problem, 

Problem Statement:- Where we are given an integer array of 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. 

 Example 1:  
 Input: coins = [5,10]  and  amount = 8
 Output: 0 

In the above example, the Output is 0 because there is no way we can create any combination from the given array to sum 8.

 Example 2:  
 Input: coins = [1,5,10] and  amount = 8
 Output: 2

In example 2, the output is 2 because we can sum 8 in 2 ways from the given array.

 Option 1 :- 1+1+1+1+1+1+1+1 = 8  
 Option 2 :- 5+1+1+1 = 8  

Let's try to solve this in code using a Dynamic Programming approach.


Happy Coding and Keep Sharing!! Code Repo

No comments:

Post a Comment