#3410

Maximize Subarray Sum After Removing All Occurrences of One Element

hard · 22.9% accepted · 60 likes · top 3%

array · dynamic programming · segment tree

⊣ practice⊣ open on leetcode ↗

Description

You are given an integer array nums.

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

- Choose any integer x such that nums remains non-empty on removing all occurrences of x.

- Remove all occurrences of x from the array.

Return the maximum subarray sum across all possible resulting arrays.

Solution