```
int maxSubArray(vector<int>& nums) {
int sum = 0, max_sum = INT32_MIN;
for (auto n : nums) {
sum = max(sum + n, n); // extend an existing subarray with 'n' OR start a new subarray with 'n'
max_sum = max(max_sum, sum);
}
return max_sum;
}
```