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