Maximum Erasure Value
MediumSliding Windowsliding window
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an array of positive integers nums. You may erase exactly one contiguous subarray, but only if every element in it is distinct. The score of the erasure is the sum of the erased elements.
Return the maximum score you can obtain.
Aim for O(n) time.
Examples
Input: nums = [2,7,2,1,7,9]
Output: 19
The subarray [2,1,7,9] has all distinct values and sums to 19.
Input: nums = [4,4,4]
Output: 4
Any subarray longer than one element repeats 4.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^4
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.