My solution is failing for some of the inputs. Please, let me know what I am missing
Coin Change problem solution in failing for some inputs
hello @S18APP-OL0003
I didnt get ur approach.
In this question u need to tell the number of ways of making change .
check this article -> https://www.geeksforgeeks.org/coin-change-dp-7/
Sorry, i forgot to mention i have written this code to find the minimum number of coin required for any amount.
Could you please suggest why the code that i have written is not working fine for finding minimum coins required.
update ur min only when q1 != Integer.MAX_VALUE.
rest evrything is correct in ur code.
okay thanks @aman212yadav - but how we can get to know that we need to add these kinds of checks as well. Because if we go by recursion tree and stack diagram we won’t find that these kinds of checks are required. How we can identify it ?
And as this code is working fine for most of the other scenarios as well.
Integer.MAX_VALUE. is indicating that change not possible right.
so if q1 contains Integer.MAX_VALUE. that indicates that our algorithm is not able to split amount-coins[i] hence subtracting coins[i] from amount is an invalid move and we should not include this move in our answer.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.