Skip to content
New
Loading problem
Maximum Subarray · medium greedy interview problem · Larpy
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
More greedy problems
Largest Number From Concatenation
medium
Jump Game
medium
Valid Parenthesis String
medium
Gas Station
medium
Hand of Straights
medium
Partition Labels
medium