Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Maximum Subarray (Easy 53)

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Solution:

Click here Current maximum subarray problem up to index is to either start from this element and include it, or continue with previous best. So this boils down to prevSum = max(prevSum + nums[i], nums[i]). Maximum of prevSums is the answer. O(n) time, O(1) space.



Installation

Run make to run python and Swift files.