6
0
:0
0
Top Momentum Slice
Top Momentum Slice
Medium
Dynamic Programming
In "Top Momentum Slice", 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,7,-1,8,-3,9]Output:
20For input nums = [-2,7,-1,8,-3,9], the contiguous subarray [7,-1,8,-3,9] gives the maximum sum 20. Therefore, return 20.
Example 2
Input:
nums = [7,-1,-2,11,-1,2]Output:
16For input nums = [7,-1,-2,11,-1,2], the contiguous subarray [7,-1,-2,11,-1,2] gives the maximum sum 16. Therefore, return 16.
Constraints
1 <= nums.length <= 105-104 <= nums[i] <= 104
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[-2,7,-1,8,-3,9]Expected Output:
20Test Case 2
Input:
[7,-1,-2,11,-1,2]Expected Output:
16