


‘N’ = 3, ‘coins’ = {1, 2, 3}, ‘freq’ = {1, 1, 3}, ‘V’ = 6
For the given example, we can make six by using the following coins:
{1, 2, 3}
{3. 3}
Hence, the answer is 2.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘N’ denoting the total number of coins.
The second line of the test case contains ‘N’ integers denoting the elements of the array ‘coins’.
The third line of the test case contains ‘N’ integers denoting the elements of the array ‘freq’.
The fourth line of the test case contains the integer ‘V’ denoting the change we want.
For each test case, print a single integer denoting the total number of possible ways to get change ‘V’.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 100
1 <= coins[i] <= 100
1 <= freq[i] <= 100
1 <= V <= 100
Time limit: 1 sec
In this approach, we will check whether we can make the required change for the current selected coin or we have to go to the next coin. So, basically we will check all the possible combinations which can be made from the given coins.
The steps are as follows:
In this approach, we will check whether we can make the required change for the current selected coin or we have to go to the next coin but to reduce the time complexity we will use a dp array to store all the values we have calculated.
The steps are as follows:
‘coinChangeHelper(coins, freq, V, supply, index, dp)’:
In this approach, we will iterate through the arrays ‘coins’ and ‘freq’, and for each coin, we will calculate the total ways to make all the coins from 1 to ‘V’ and update the dp array.
The steps are as follows: