Trains the technique from
LeetCode 92Reverse Linked List IIThis 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 pipeline is instrumented with gauges wired in a single direction: every gauge holds one signed drift reading and points at the gauge downstream of it, and the final gauge points at nothing.
The harness only carries plain JSON, so the chain reaches you as the array drifts, listing the readings from the first gauge through to the last. Your answer takes the same shape: the readings of the rewired chain, first gauge first.
Gauges are numbered from 1. Turn the run of gauges from position left through position right around, so the gauge that was last in that run now comes first and the gauge that was first in it now comes last. Everything outside the run keeps its place, and the run stays joined to whatever sat on either side of it.
Do this by rewiring, not by copying readings into a fresh chain: rebuild the gauges from the array, redirect the wires, and beyond those gauges and the array you hand back hold only a fixed number of gauge references. Walk the chain once.
Example 1
Gauges at positions 2 through 5 carry -4, 0, 7 and 9; after rewiring that run reads 9, 7, 0, -4, while the gauges at positions 1 and 6 stay put.
Example 2
The run covers the whole chain, so the two gauges trade places.
Example 3
A run of one gauge has nothing to turn around, so the chain is handed back unchanged.
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 flip_chain_span(drifts: list[int], left: int, right: int) -> list[int]:public int[] flipChainSpan(int[] drifts, int left, int right)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.