Maximum Erasure Value
MediumSliding Window
Decode it first. Clues, constraints, pattern and plan before any code.Given an array of positive integers nums, you may erase exactly one subarray whose elements are all unique. Your score is the sum of the erased elements. Return the maximum score you can get.
nums = [4, 2, 4, 5, 6] → 17 ([2, 4, 5, 6])
nums = [5, 2, 1, 2, 5, 2, 1, 2, 5] → 8 ([5, 2, 1] or [1, 2, 5])Constraints
1 <= nums.length <= 10^51 <= nums[i] <= 10^4