53. Maximum Subarray
Intitution
The key idea is to maintain a running sum of the subarray and reset it whenever it becomes negative. A negative sum will only reduce the total of future subarrays, so we discard it and start fresh. We also keep track of the maximum sum seen so far while iterating.
Complexity
Space Complexity
Time Complexity
Code
Last updated