@san89kalp That was a helpful video for getting the insight with the negative numbers. Here's my spin on the solution (in JavaScript):

var maxSubArray = function(nums) {
let maxConsec = -Infinity;
let maxSoFar = -Infinity;
nums.forEach(function(n){
maxConsec = Math.max(n, n + maxConsec);
maxSoFar = Math.max(maxSoFar, maxConsec);
});
return maxSoFar;
};

Using JavaScript's forEach() for better readability.

Using -Infinity because nums[0] would be repeated in forEach. Only 1 index so not much affect on time complexity.

And now this:

maxConsecutiveSum = Math.max(n, n + maxConsecutiveSum);

Why: What it ends up doing is it basically starts the consecutive sum at a positive number, and then "tracks" a consecutive sum after that. If it sets the consecutive sum equal to the current number, it's like re-starting sum at that number, especially if number > number + consecutive sum, which can only happen if the consecutive sum is negative.