Error coming in test cases when max sum includes the 0th element of the array

for(int i=0;i<n;i++)
//here i is starting from 0.
//in the condition,
currentSum=cumsum[j]-cumsum[i-1]
//if(i==0) then cumsum[i-1] will be cumsum[-1]., that is not defined thus giving error.
can u explain how to fix it?

Hello @sidharth.delhi12_20344cb0d809bedb,

Just check if i is 0 or not like this,

currentSum = cumSum[j];
if(i!=0){
     currentSum -= cumSum[i-1]
} 

I think this will work now

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.