medium

Maximum Subarray

Given an integer array containing at least one element, find the contiguous subarray with the largest sum and return that sum.

Constraints
  • 1 ≤ n ≤ 10^5
  • -10^4 ≤ nums[i] ≤ 10^4
Examples
in: nums = [-2,1,-3,4,-1,2,1,-5,4]
out: 6
[4,-1,2,1].

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.