← Practice · Dynamic programming
Maximum Subarray Medium
Given an integer array nums, find the contiguous subarray (at least one element) with the largest sum and return that sum.
Examples
[-2,1,-3,4,-1,2,1,-5,4] -> 6 (subarray [4,-1,2,1])[1] -> 1
Define a function named maxSubArray in JavaScript.
00:00▶ Visualize
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests