← All problems
Maximum Subarray (Kadane's Algorithm)
EasyDP
Given an integer array `nums`, find the contiguous subarray (containing at least one number) which has the largest sum, and return its sum.
Examples
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Subarray [4,-1,2,1] has sum 6.
Input: nums = [1]
Output: 1
Input: nums = [5,4,-1,7,8]
Output: 23
Hints
Solution
Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 5 test cases.