6
0
:0
0
Ad Trend Maximum
Ad Trend Maximum
Hard
Dynamic Programming
In "Ad Trend Maximum", 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,18,-1,19,-3,20]Output:
53For input nums = [-2,18,-1,19,-3,20], the contiguous subarray [18,-1,19,-3,20] gives the maximum sum 53. Therefore, return 53.
Example 2
Input:
nums = [18,-1,-2,22,-1,2]Output:
38For input nums = [18,-1,-2,22,-1,2], the contiguous subarray [18,-1,-2,22,-1,2] gives the maximum sum 38. Therefore, return 38.
Constraints
1 <= nums.length <= 105-104 <= nums[i] <= 104
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[-2,18,-1,19,-3,20]Expected Output:
53Test Case 2
Input:
[18,-1,-2,22,-1,2]Expected Output:
38