Trains the technique from
LeetCode 3487Maximum Unique Subarray Sum After DeletionThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
Discarding the repeats leaves 1, 2 and 3 side by side, and every value above zero counted once comes to 6.
Example 2
Every chip is below zero and one has to be kept, so the least bad single chip is the best on offer.
Example 3
Discarding the two negatives and one of the two 4 chips leaves 4 and 2 next to each other for 6.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_sum(chips: list[int]) -> int:public int maxSum(int[] chips)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.