Help with error

sol : https://ide.codingblocks.com/s/419587

it is giving the correct answer until I use the dp array,
I have commented it out.

amount can be negative
hence dp[amount] will give error
so first check the amount
like this
if(amount>0 && dp[amount] != -1)

I tried but still the answer and aren’t we checking if amount - coin[i] >= 0 so how can the answer be negative

there are many other errors as well
you have to initialise the dp array with -1
check if the function return value is -1 or not

Modified Code

this code give correct output for smaller testcases but give TLE for large
because of multiple recursive calls