hardArrayDynamic ProgrammingSegment Tree 0 views

Maximize Subarray Sum After Removing All Occurrences of One Element

You are given an integer array nums.

You are given an integer array nums.

You can do the following operation on the array at most once:

Return the maximum subarray sum across all possible resulting arrays.

Maximize Subarray Sum After Removing All Occurrences of One Element diagram

Example 1

Input: nums = [-3,2,-2,-1,3,-2,3]

Output: 7

Explanation: We can have the following arrays after at most one operation: The output is max(4, 4, 7, 4, 2) = 7 .

Example 2

Input: nums = [1,2,3,4]

Output: 10

Explanation: It is optimal to not perform any operations.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^6 <= nums[i] <= 10^6

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.