Trains the technique from
LeetCode 143Reorder 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 radio link runs through repeater stations coupled in one direction: each station carries an integer gain and points at the station downstream of it, and the last station points at nothing.
Because the harness passes plain JSON, the link arrives as the array stations, holding the gains from the head station through to the tail station. Your answer takes the same shape: the gains of the recoupled link, head station first.
Re-cable the link so it alternates between the two ends. The head station leads, the tail station follows it, then the second station, then the second-from-last, and so on until every station has been placed exactly once. Only the couplings change: no station is duplicated, dropped, or has its gain rewritten.
Do the work on the couplings themselves rather than by copying gains into a fresh link. Rebuild the stations from the array, then relink them, and beyond those stations and the array you hand back keep only a fixed number of station references.
Example 1
The head station keeps the lead, the tail station couples behind it, then the second station, and the second-from-last station closes the link.
Example 2
Three stations from the front interleave with three from the back, so the two halves zip together.
Example 3
An odd count leaves one station unpaired, so the middle station with gain 4 ends up at the tail.
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 fold_relay_chain(stations: list[int]) -> list[int]:public int[] foldRelayChain(int[] stations)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.