6
0
:0
0
Best Growth Range
Best Growth Range
Hard
Dynamic Programming
In "Best Growth Range", 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,11,-1,12,-3,13]Output:
32For input nums = [-2,11,-1,12,-3,13], the contiguous subarray [11,-1,12,-3,13] gives the maximum sum 32. Therefore, return 32.
Example 2
Input:
nums = [11,-1,-2,15,-1,2]Output:
24For input nums = [11,-1,-2,15,-1,2], the contiguous subarray [11,-1,-2,15,-1,2] gives the maximum sum 24. Therefore, return 24.
Constraints
1 <= nums.length <= 105-104 <= nums[i] <= 104
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[-2,11,-1,12,-3,13]Expected Output:
32Test Case 2
Input:
[11,-1,-2,15,-1,2]Expected Output:
24