49. Maximum Subarray

MediumDynamic Programming

Given an integer array nums, find the contiguous subarray (containing at least one element) which has the largest sum, and return its sum. A subarray is a contiguous part of the array. For example, in [-2,1,-3,4,-1,2,1,-5,4], the subarray [4,-1,2,1] has the largest sum of 6.

Examples

Input: [-2,1,-3,4,-1,2,1,-5,4]

Output: 6

Explanation: Public test case for Maximum Subarray

Constraints

  • 1 <= nums.length <= 10^5
  • -10^4 <= nums[i] <= 10^4
Loading...

Run checks all cases above. Submit evaluates all test cases.