Skip to content
Decoder

Maximum Erasure Value

Medium

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^5
  • 1 <= nums[i] <= 10^4

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.