Skip to content
6
0
:
0
0

Maximum Profit Span: Ad Campaign Edition

Medium

Dynamic Programming

In "Maximum Profit Span: Ad Campaign Edition", 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,24,-1,25,-3,26]
Output:71

For input nums = [-2,24,-1,25,-3,26], the contiguous subarray [24,-1,25,-3,26] gives the maximum sum 71. Therefore, return 71.

Example 2

Input:nums = [24,-1,-2,28,-1,2]
Output:50

For input nums = [24,-1,-2,28,-1,2], the contiguous subarray [24,-1,-2,28,-1,2] gives the maximum sum 50. Therefore, return 50.

Constraints

  • 1 <= nums.length <= 105
  • -104 <= nums[i] <= 104
solution.js
Loading...

Test Cases (2)

Test Case 1
Input:
[-2,24,-1,25,-3,26]
Expected Output:
71
Test Case 2
Input:
[24,-1,-2,28,-1,2]
Expected Output:
50