53. Maximum Subarray

Practice Maximum Subarray for free on NudgeCode: Medium, Greedy pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return the largest sum of a non-empty contiguous subarray of nums.

Example

nums = [-2,1,-3,4,-1,2,1,-5,4]  ->  6   ([4,-1,2,1])
nums = [5,4,-1,7,8]             ->  23

Constraints