Line Number 35, getting ArrayIndexOutOfBoundsException: -1 as cumSum[i-1] could raise since i starts from 0;
CPP - Maximum Subarray Sum 2
Hello @Ans
You can change it to
if(i == 0) {
currentSum = cumSum[j];
} else {
currentSum = cumSum[j] - cumSum[i-1];
}
This error depends from IDE to IDE
The IDE which the mentor is using is ide.codingblocks.com and this IDE doesn’t produce an error but just assumes the value to be 0.
2 Likes