LeetCode 53 Maximum Subarray - Problem Statement

The problem

Find the contiguous subarray with the largest sum.

With nums = [-2,1,-3,4,-1,2,1,-5,4]:

  • Subarray [4,-1,2,1] has sum 66.
  • No contiguous subarray has a larger sum.
  • Answer: 66.

With nums = [1]:

  • Only one element. Answer: 11.

With nums = [5,4,-1,7,8]:

  • Entire array: 5+41+7+8=235 + 4 - 1 + 7 + 8 = 23.
  • Answer: 2323.

Constraints: 11 \le nums.length 105\le 10^5.