cSum[i-1] will give garbage value if i = 0

If i = 0 then
currentSum = cSum[j] - cSum[i-1]
will give garbage value because cSum[i-1] is cSum[-1].

The cSum[-1] will give garbage value.

Hello @JoKeR,

Thanks for pointing out the mistake in the code.
I’ll convey the same to your mentors.

The solution for that is:
Create the cSum[n+1] of size n;
and do
cSum[0]=0;
So, the formula will become:
currentSum = cSum[j+1] - cSum[i]

Hope, this would help.
give a like if you are satisfied.