Skip to content
6
0
:
0
0

Best Sales Streak

Medium

Dynamic Programming

In "Best Sales Streak", 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,2,-1,3,-3,4]
Output:5

For input nums = [-2,2,-1,3,-3,4], the contiguous subarray [2,-1,3,-3,4] gives the maximum sum 5. Therefore, return 5.

Example 2

Input:nums = [2,-1,-2,6,-1,2]
Output:7

For input nums = [2,-1,-2,6,-1,2], the contiguous subarray [6,-1,2] gives the maximum sum 7. Therefore, return 7.

Constraints

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

Test Cases (2)

Test Case 1
Input:
[-2,2,-1,3,-3,4]
Expected Output:
5
Test Case 2
Input:
[2,-1,-2,6,-1,2]
Expected Output:
7