6
0
:0
0
Season Score Streak
Season Score Streak
Medium
Dynamic Programming
In "Season Score 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,14,-1,15,-3,16]Output:
41For input nums = [-2,14,-1,15,-3,16], the contiguous subarray [14,-1,15,-3,16] gives the maximum sum 41. Therefore, return 41.
Example 2
Input:
nums = [14,-1,-2,18,-1,2]Output:
30For input nums = [14,-1,-2,18,-1,2], the contiguous subarray [14,-1,-2,18,-1,2] gives the maximum sum 30. Therefore, return 30.
Constraints
1 <= nums.length <= 105-104 <= nums[i] <= 104
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[-2,14,-1,15,-3,16]Expected Output:
41Test Case 2
Input:
[14,-1,-2,18,-1,2]Expected Output:
30