Skip to content
6
0
:
0
0

Heatmap High Segment

Easy

Dynamic Programming

In "Heatmap High Segment", 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,10,-1,11,-3,12]
Output:29

For input nums = [-2,10,-1,11,-3,12], the contiguous subarray [10,-1,11,-3,12] gives the maximum sum 29. Therefore, return 29.

Example 2

Input:nums = [10,-1,-2,14,-1,2]
Output:22

For input nums = [10,-1,-2,14,-1,2], the contiguous subarray [10,-1,-2,14,-1,2] gives the maximum sum 22. Therefore, return 22.

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,10,-1,11,-3,12]
Expected Output:
29
Test Case 2
Input:
[10,-1,-2,14,-1,2]
Expected Output:
22