Home

Maximum Subarray

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous portion of an array.

The maximum subarray is bolded in the sample tests below, but you only need to return its sum.

Hint: Try a sliding window approach!

maximumSubarray([4, -5, 2, 5]) → 7
maximumSubarray([-2, 1, -3, 4, -1, 2, 1, -5, 4]) → 6
maximumSubarray([6, -5, 2, 5]) → 8

😳 TIME LEFT: seconds 😳

function maximumSubarray(nums) {

}

TOTAL TIME: seconds