Dev
Mentor
Coach Interview AI
Mock Interview AI
Coding Problems
Blog
Pricing
Toggle theme
Sign In
Get Started
Toggle theme
Loading...
For the best coding experience, use a desktop browser.
Medium
Array
Maximum Subarray
Find the contiguous subarray with the largest sum and return that sum.
Examples
Input:
nums = [-2,1,-3,4,-1,2,1,-5,4]
Output:
6
[4,-1,2,1] sums to 6.
Sample Test Cases
Case 1 Input:
[-2,1,-3,4,-1,2,1,-5,4]
Expected:
6
Case 2 Input:
[1]
Expected:
1
Reset
Run
Submit
Loading editor...
Test Case
Output
Submission
Case 1 Input:
[-2,1,-3,4,-1,2,1,-5,4]
Expected:
6
Case 2 Input:
[1]
Expected:
1