Solution relies on knowing the highest possible sum when looking at the subarray to the right (iterating in reverse).

```
int maxSubArray(int A[], int n) {
int res = A[0], rightSum = 0;
for(int i = n-1; i >= 0; --i){
rightSum = max(A[i], A[i] + rightSum);
res = max(res, rightSum);
}
return res;
}
```