Skip to content
6
0
:
0
0

Revenue Boost Interval

Hard

Dynamic Programming

In "Revenue Boost Interval", 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,8,-1,9,-3,10]
Output:23

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

Example 2

Input:nums = [8,-1,-2,12,-1,2]
Output:18

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

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,8,-1,9,-3,10]
Expected Output:
23
Test Case 2
Input:
[8,-1,-2,12,-1,2]
Expected Output:
18