Maximum subarray 2

in the code for maximum subarray 2 we have
currentSum=cum[j] - cumSum[i-1]
for i=0 index will be -1.it should cause memory error

@sharad1103 Yes you should prevent negative indexes in the array as it may have some unexpected results depending on the compiler. But here it is not causing any error and taking cumSum[-1] as 0. It basically depends on the compiler.

but if i declare somewhere in the code curSum[-1], it is causing an error.

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.