Skip to content
6
0
:
0
0

Prime Window Gain

Easy

Dynamic Programming

In "Prime Window Gain", 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,15,-1,16,-3,17]
Output:44

For input nums = [-2,15,-1,16,-3,17], the contiguous subarray [15,-1,16,-3,17] gives the maximum sum 44. Therefore, return 44.

Example 2

Input:nums = [15,-1,-2,19,-1,2]
Output:32

For input nums = [15,-1,-2,19,-1,2], the contiguous subarray [15,-1,-2,19,-1,2] gives the maximum sum 32. Therefore, return 32.

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,15,-1,16,-3,17]
Expected Output:
44
Test Case 2
Input:
[15,-1,-2,19,-1,2]
Expected Output:
32