Cummulative sum method

the formula to find the curent sum is given as csum[j]-csum[i-1] but if we are finding the sum of a subarray from index ehere i =0 and j=0 then i -1 will go out of bound
please let me know if i am wrong

hello @Abhay-Chauhan-1546158815521966 yes this problem has been reported and please wait this will be resolved in sometime.
Happy Learning!!

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.

Hi @tusharaggarwal272 I am also facing same problem. Can u please share the correct solution.

instead of just writing :

current_sum = cum_sum[j] - cum_sum[i-1];

write like below:

if(i==0)

        {

            current_sum = cum_sum[j] - 0;

        }

        else

        {

            current_sum = cum_sum[j] - cum_sum[i-1];

        }

instead of just writing :

current_sum = cum_sum[j] - cum_sum[i-1];

write like below:

if(i==0)

        {

            current_sum = cum_sum[j] - 0;

        }

        else

        {

            current_sum = cum_sum[j] - cum_sum[i-1];

        }

@ratiktiwari It worked. Thanks

1 Like