MAXIMUM SUBARRAY APPROACH 2

IN THIS CUMULATIVE SUM APPROACH, (when we have to find the sum from ith place to jth place in the array,then we are using this below formula).

sum=CS[j]-CS[i-1];

suppose our i=0 and j=5, then it is showing wrong results??

@CODER_JATIN,
Because index can not be -1.

Yes , that why i’m asking that this approach will fail if we also count the 0th index???

@CODER_JATIN,
You can either just shift everything to be 1-indexed, or put a simple if statement when l=0, because if l=0, you only need the sum of prefix till r, which is already stored in CS[r], basically, -CS[-1] would only mean -0, so why bother doing it.