Maximum Erasure Value
Real-world version: Richest Run Of Distinct BinsThe statement here is our own: the same inputs, outputs and technique.
A picking aisle is a row of bins. bins[i] is the part number stored in bin i, and clearing a bin earns that many points. The same part number may be stored in more than one bin.
A picker clears one contiguous stretch of bins, and the audit only accepts the run when no part number appears twice inside it. Return the largest number of points such a run can earn.
Examples
Example 1
- Input
- bins = [1, 5, 4, 5]
- Output
- 10
Clearing bins 0 through 2 collects part numbers 1, 5 and 4, which are all different, for 10 points. Adding bin 3 would repeat part number 5, so that run is not accepted.
Example 2
- Input
- bins = [4, 2, 7, 9]
- Output
- 22
No part number appears twice anywhere, so the whole aisle is one accepted run worth 4 + 2 + 7 + 9 = 22 points.
Example 3
- Input
- bins = [2, 1, 2, 1, 2, 1, 2]
- Output
- 3
Any accepted run holds at most one bin of part number 2 and one of part number 1, so a run such as bins 0 and 1 earns 3 points.
Constraints
- 1 <= bins.length <= 10^5
- 1 <= bins[i] <= 10^4
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def maximum_unique_subarray(bins: list[int]) -> int:public int maximumUniqueSubarray(int[] bins)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's