Back to the 100
Problem 052Dynamic Programming
Medium

Maximum Subarray

052

Given a non-empty integer array nums, return the largest sum of any contiguous subarray.

EXAMPLES

Example 1
Input
{
  "nums": [
    -2,
    1,
    -3,
    4,
    -1,
    2,
    1,
    -5,
    4
  ]
}

Output
6

FUNCTION SHAPE

nums: intArrayint
00:00
3 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.