Trains the technique from
LeetCode 83Remove Duplicates from Sorted ListThis 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 freeze-dryer runs a recipe built from holds wired one behind another. A hold knows only its target temperature in Celsius and which hold comes after it, and nothing in the machine records how many holds a recipe has. Targets never fall as the run proceeds, and neighbouring holds may carry the same target.
The recipe reaches you as holds, a flat list of the target temperatures in run order. That flat list is the JSON stand-in for the wired chain, so [] stands for a recipe with no holds in it at all, and the answer is a flat list of the same kind.
A hold that repeats the target of the hold in front of it changes nothing about the run, so unhook every such hold and hand back the chain that remains, in run order. Each target that appears in the recipe has to appear exactly once in the answer. Unhook the repeats from the chain you were handed instead of assembling a fresh chain alongside it.
Example 1
The second -40 repeats the hold in front of it, and two of the three 5 holds do the same, so those three unhook and the chain keeps -40, -12 and 5 in run order.
Example 2
The second hold repeats the first, so it unhooks and one hold at 8 is left.
Example 3
No hold repeats the target in front of it, so the chain comes back untouched.
Example 4
A recipe with no holds has nothing to unhook, so the answer is an empty chain.
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 trim_repeat_holds(holds: list[int]) -> list[int]:public int[] trimRepeatHolds(int[] holds)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.