Problem
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.
Example 1
- Input
- nums = [4, 2, 4, 5, 6]
- Output
- 17
- Why
- [2, 4, 5, 6]
Example 2
- Input
- nums = [5, 2, 1, 2, 5, 2, 1, 2, 5]
- Output
- 8
- Why
- [5, 2, 1] or [1, 2, 5]
Constraints
1 <= nums.length <= 10^51 <= nums[i] <= 10^4