Calculate current sun using commutative sum

How did we derive the equation
currentSum=cumSum[j]-cumSum[i-1] ?
And what is the case when i=0?
cumSum[-1]??

hello @kartikaydwivedi55

handle i=0 case seprately . becuase for i=0 we cannot access i-1 (-1 index).

add this->

if(i==0) 
currentSum=cumSum[j]
else
currentSum=cumSum[j]-cumSum[i-1] 

sum of element between (i,j) = sum of elements between (1,j) - sum of elements between (1,i-1)
note-> i and j r indices

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.