Reverse Linked List
Real-world version: Rewind the Telemetry ChainThe statement here is our own: the same inputs, outputs and technique.
A probe stores its telemetry as a one-way chain of frames: every frame carries a signed reading and a link to the frame recorded after it, and the final frame links to nothing.
Because the harness passes plain JSON, the chain reaches you as the array frames, holding the readings in order from the front frame to the last one. An empty array means the chain has no frames at all. Your answer must use the same shape: the readings of the rebuilt chain, front frame first.
Turn the chain around so the frame that was last becomes the front and every link points at the frame that used to precede it. Solve it the way the chain itself demands: rebuild the frames, then walk them once and redirect one link at a time, carrying the frame behind you as you go. Beyond the frames themselves and the array you return, only a fixed number of frame references may be held.
Examples
Example 1
- Input
- frames = [4, -1, 9, 9, -12]
- Output
- [-12, 9, 9, -1, 4]
The frame holding -12 was last, so it becomes the front, and the readings come back in the opposite order. Repeated readings keep both copies.
Example 2
- Input
- frames = [30, -30]
- Output
- [-30, 30]
With two frames the single link between them flips, so the second frame leads.
Example 3
- Input
- frames = [7]
- Output
- [7]
A lone frame has no link to redirect, so the chain comes back unchanged. A chain of zero frames likewise answers with an empty chain.
Constraints
- 0 <= frames.length <= 5000
- -5000 <= frames[i] <= 5000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def rewind_telemetry_chain(frames: list[int]) -> list[int]:public int[] rewindTelemetryChain(int[] frames)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 8 test cases: 8 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's