Trains the technique from
LeetCode 287Find the Duplicate NumberThis 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 packing line drops every parcel into one of n numbered chutes, labelled 1 through n. The shift log codes records the chute label used for each parcel, and the shift handled n + 1 parcels, so codes has length n + 1.
One chute was wired to two buttons, so its label got reused: exactly one label occurs two or more times in codes, and every other label that occurs at all occurs exactly once. Some labels may never occur.
Return the label that was reused.
The log is archived material: your routine must leave codes unchanged and use only a constant amount of extra space beyond the input.
Example 1
Five parcels were logged, so there are four chutes. Label 4 shows up at positions 0 and 2 while labels 1, 2 and 3 each show up once.
Example 2
Seven parcels means six chutes. Label 6 was used three times, labels 1, 2, 3 and 5 once each, and label 4 never came up.
Example 3
With a single chute and two parcels, that one label has to carry both.
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 reused_chute(codes: list[int]) -> int:public int reusedChute(int[] codes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.