6
0
:0
0
Pulse Peak Subarray
Pulse Peak Subarray
Medium
Dynamic Programming
In "Pulse Peak Subarray", 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,17,-1,18,-3,19]Output:
50For input nums = [-2,17,-1,18,-3,19], the contiguous subarray [17,-1,18,-3,19] gives the maximum sum 50. Therefore, return 50.
Example 2
Input:
nums = [17,-1,-2,21,-1,2]Output:
36For input nums = [17,-1,-2,21,-1,2], the contiguous subarray [17,-1,-2,21,-1,2] gives the maximum sum 36. Therefore, return 36.
Constraints
1 <= nums.length <= 105-104 <= nums[i] <= 104
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[-2,17,-1,18,-3,19]Expected Output:
50Test Case 2
Input:
[17,-1,-2,21,-1,2]Expected Output:
36