Skip to content
6
0
:
0
0

Value Run Optimizer

Easy

Dynamic Programming

In "Value Run Optimizer", 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,20,-1,21,-3,22]
Output:59

For input nums = [-2,20,-1,21,-3,22], the contiguous subarray [20,-1,21,-3,22] gives the maximum sum 59. Therefore, return 59.

Example 2

Input:nums = [20,-1,-2,24,-1,2]
Output:42

For input nums = [20,-1,-2,24,-1,2], the contiguous subarray [20,-1,-2,24,-1,2] gives the maximum sum 42. Therefore, return 42.

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,20,-1,21,-3,22]
Expected Output:
59
Test Case 2
Input:
[20,-1,-2,24,-1,2]
Expected Output:
42