Skip to content
6
0
:
0
0

Market Surge Sequence

Medium

Dynamic Programming

In "Market Surge Sequence", each integer represents gain or loss at each time step.

Find the maximum possible sum of a contiguous non-empty segment.

Example 1

Input:nums = [-2,12,-1,13,-3,14]
Output:35

For input nums = [-2,12,-1,13,-3,14], the contiguous subarray [12,-1,13,-3,14] gives the maximum sum 35. Therefore, return 35.

Example 2

Input:nums = [12,-1,-2,16,-1,2]
Output:26

For input nums = [12,-1,-2,16,-1,2], the contiguous subarray [12,-1,-2,16,-1,2] gives the maximum sum 26. Therefore, return 26.

Constraints

  • 1 <= nums.length <= 105
  • -104 <= nums[i] <= 104
solution.js
Loading...

Test Cases (2)

Test Case 1
Input:
[-2,12,-1,13,-3,14]
Expected Output:
35
Test Case 2
Input:
[12,-1,-2,16,-1,2]
Expected Output:
26