Skip to content
6
0
:
0
0

Best Sales Streak: Quarterly Revenue Edition

Medium

Dynamic Programming

In "Best Sales Streak: Quarterly Revenue 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,22,-1,23,-3,24]
Output:65

For input nums = [-2,22,-1,23,-3,24], the contiguous subarray [22,-1,23,-3,24] gives the maximum sum 65. Therefore, return 65.

Example 2

Input:nums = [22,-1,-2,26,-1,2]
Output:46

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

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,22,-1,23,-3,24]
Expected Output:
65
Test Case 2
Input:
[22,-1,-2,26,-1,2]
Expected Output:
46