What is the error in my code?

hi @goyalvivek
refer this code -->


Hope it clears your doubt…

https://ide.codingblocks.com/s/277548 please check

hi @goyalvivek
its giving the correct o/p only…

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

chack in it https://ide.codingblocks.com/s/650961

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)

yes sir, ur code is fine, i am asking abt my code https://ide.codingblocks.com/s/650961

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.