MIn coin change top down approach

this testcase is not giving the correct ans .
18 // value
3 // no of coins
6 8 10 // value of coins
My code link is

@avinashmallik2017,

  • Line 10: int ans = INT_MAX;
    Consider this function call -> F(18) -> F(8) -> F(2):
    Now F(2) will return INT_MAX, and in the parent call F(8): Line 14:

    ans = min(ans,subprob+1);

subprob is INT_MAX, thus suburb+1 = INT_MIN, which would eventually yield itself as answer.

Try this instead:

  • Line 10: int ans = INT_MAX-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.