Not giving desired output

code- https://ide.codingblocks.com/s/321871

Hey @anubhavb11
You can’t initialize dp array to -1 like that ,it works for 0 only
int dp[100]={-1};
this will make dp[0]=-1 but rest dp[i] will be 0
so run a loop instead and set dp[i]=-1;
Or use memset(dp,-1,sizeof(dp)) this initializes dp array with -1

1 Like

ok thank you i got it
why it only work with 0?

Please mark it as resolved :slight_smile:

why it only work with 0?

Because 0 is taken as default for all the non filled values while initializing arrays.

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.

1 Like