Why is the value of right and left initialized with the value of -1 ?
Is it compulsory to have -1 or can we begin those variables with 0 also?
Maximum subarray using cumulative array
Also please explain, in maximum subarray using cumulative array,
currsum=cumsum[j]-cumsum[i-1];
since the value of i has been initialized from 0, therefore on putting i=0, we get currsum=cumsum[0]-cumsum[-1]
so I don’t know how can we find the value of cumsum[-1] ?
…
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 cum[-1] as 0. It basically depends on the compiler.
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.