Calculating Maximum Subarray using cumulative sum

Hi, Team here is my question,
While subtracting the CumulativeSum[j] - CumulativeSum[i-1], shouldn’t we be getting an array out of bound error in exception for j = i and i = 0. As that would mean CumulativeSum[0] - CumulativeSum[-1].

Also how can we cover the case when the first element in the array is the maximu subarray.

hello @kcabir
yeah u are right . we need to handle the case separately when i=0.
add an if condition for i=0 .
after adding if condition this algorithm will work for all the cases.

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.