6
0
:0
0
Peak Energy Window: Sensor Peak Edition
Peak Energy Window: Sensor Peak Edition
Hard
Dynamic Programming
In "Peak Energy Window: Sensor Peak Edition", 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,23,-1,24,-3,25]Output:
68For input nums = [-2,23,-1,24,-3,25], the contiguous subarray [23,-1,24,-3,25] gives the maximum sum 68. Therefore, return 68.
Example 2
Input:
nums = [23,-1,-2,27,-1,2]Output:
48For input nums = [23,-1,-2,27,-1,2], the contiguous subarray [23,-1,-2,27,-1,2] gives the maximum sum 48. Therefore, return 48.
Constraints
1 <= nums.length <= 105-104 <= nums[i] <= 104
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[-2,23,-1,24,-3,25]Expected Output:
68Test Case 2
Input:
[23,-1,-2,27,-1,2]Expected Output:
48