Skip to content
6
0
:
0
0

Campaign Gain Segment: Trading Session Edition

Easy

Dynamic Programming

In "Campaign Gain Segment: Trading Session 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,25,-1,26,-3,27]
Output:74

For input nums = [-2,25,-1,26,-3,27], the contiguous subarray [25,-1,26,-3,27] gives the maximum sum 74. Therefore, return 74.

Example 2

Input:nums = [25,-1,-2,29,-1,2]
Output:52

For input nums = [25,-1,-2,29,-1,2], the contiguous subarray [25,-1,-2,29,-1,2] gives the maximum sum 52. Therefore, return 52.

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,25,-1,26,-3,27]
Expected Output:
74
Test Case 2
Input:
[25,-1,-2,29,-1,2]
Expected Output:
52