Maximize Subarray Sum After Removing All Occurrences of One Element [LC#3410]

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.

Intuition

Code


Time complexity