Loading your interview setup
Skip to content
New
Loading
LarpCode 150
medium
· greedy
Mock interview
Maximum Subarray
Given an integer array `nums`, return the largest sum of any contiguous non-empty subarray.
Examples
in: nums = [-2,1,-3,4,-1,2,1,-5,4]
out: 6
[4,-1,2,1] sums to 6
Constraints
1 <= len(nums) <= 10^5
-10^4 <= nums[i] <= 10^4
Hints
Stuck? Show a hint (2 available)
Python
JavaScript
Java
C++
Go
Run
Submit
target: O(n) time
⌘↩ run · ⇧⌘↩ submit
see the solution