Current sum gets garbage value

currerentSum = cumulativeSum[j] - cumulativeSum[i-1]

but for i = 0 and whatever be the value of j; we are doing :
currentSum = cumulativeSum[j] - cumulativeSum[-1]; and cumulativeSum[-1] is a garbage value so this might affect the actual result and we might not get the correct maxSum and the subarray.

Yes you are correct. Go through this Negative indexing in cpp

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.