Doubt in code loop cannot have i=0

here if we take i=0 in loop the index of cs[i-1] will become -1.
how is that possible?

Hello @dhasmanasaksham572 Yes we have to add one constraint which Sir missed

if(i>=1)
current_sum = cum_sum[j] + cum_sum[i-1];
else
current_sum= cum_sum[j] ;

is this code correct?
https://ide.codingblocks.com/s/424614

@dhasmanasaksham572 check this:


you have to handle the case like this.
Happy Learning!!

what is the need of csum[n]={0}

@dhasmanasaksham572 in this we are just making the initital sum at every point as 0.
it is just a good practice.

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.