Skip to content
6
0
:
0
0

Peak Energy Window

Hard

Dynamic Programming

In "Peak Energy Window", 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,3,-1,4,-3,5]
Output:8

For input nums = [-2,3,-1,4,-3,5], the contiguous subarray [3,-1,4,-3,5] gives the maximum sum 8. Therefore, return 8.

Example 2

Input:nums = [3,-1,-2,7,-1,2]
Output:8

For input nums = [3,-1,-2,7,-1,2], the contiguous subarray [7,-1,2] gives the maximum sum 8. Therefore, return 8.

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,3,-1,4,-3,5]
Expected Output:
8
Test Case 2
Input:
[3,-1,-2,7,-1,2]
Expected Output:
8