Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Given nums = [-2, -1, 2, 1], k = 1, return 2. (because the subarray [-1, 2] sums to 1 and is the longest) Why not [-2, 2, 1]? the sum is 1 and length is 3.

Because the subarray has to be contiguous. Continuous adjacent neighbors without skipping any elements.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.