Sir,
I found 1 mistake in this tutorial, that if we use cummulative sum technique and if the max ans is having the first index element then we have to define a condition for that
Regarding Code mistake
In this tutorial code there should be a condition like this: if(i==0) sum=cummsum[j]; before the line sum=cumsum[j]-cumsum[i-1];
because in the tutorial code there is no condition like this
because in the tutorial code there is no condition like this so it will fail at n=4 arr=1,2,3,4
Hello @gods_eye,
Yes, you have pointed out the correct mistake.
I’ll convey the same to your mentors.
It will give garbage value because cSum[i-1] is cSum[-1].
cSum[-1] is a random value stored in memory at the location prior to cSum[0].
You can also do the following:
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.
okay sir now I am satisfied with the answer