Maximum Unique Subarray Sum After Deletion
Real-world version: Keeping the Best Run of Different ChipsThe statement here is our own: the same inputs, outputs and technique.
A tray holds chips whose values are chips. Values may repeat and may be below zero.
Discard as many chips as you like, so long as at least one is left. Then choose a run of neighbouring survivors in which no value turns up twice, and add its values up.
Return the largest total that can be reached.
Examples
Example 1
- Input
- chips = [1, 2, 3, 3, 2, 1]
- Output
- 6
Discarding the repeats leaves 1, 2 and 3 side by side, and every value above zero counted once comes to 6.
Example 2
- Input
- chips = [-3, -1, -2]
- Output
- -1
Every chip is below zero and one has to be kept, so the least bad single chip is the best on offer.
Example 3
- Input
- chips = [-5, 4, -3, 4, 2]
- Output
- 6
Discarding the two negatives and one of the two 4 chips leaves 4 and 2 next to each other for 6.
Constraints
- 1 <= chips.length <= 100
- -100 <= chips[i] <= 100
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 max_sum(chips: list[int]) -> int:public int maxSum(int[] chips)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 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
More on the same topics
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy
- Task SchedulerReal-world version: Press Die CooldownMedium
- Maximum Palindromes After OperationsReal-world version: Noticeboard Word StripsMedium
- Cinema Seat AllocationReal-world version: Study Pods in the Lecture HallMedium