What is the error in my code?
Why do we have to add1 in int subans = dp[n-coins[i]] + 1 ; and not in dp[n] = min(dp[n], subans) ; my ans is wrong for n = 14 and 15
hi @goyalvivek
its giving the correct o/p…
for n = 14, output will be 2 only ( two 7rs coins)
for n = 15, output will be 3 only ( two 7rs coins, one 1rs coin)
hi @goyalvivek
change[i] = min(change[i], change[i-coin[j]]) + 1;
here was the error… it should be
change[i] = min(change[i], change[i-coin[j]] + 1);
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.