AlgoScope

Reverse in Groups of k

AlgorithmintermediateLinked List Operations

Count k ahead, reverse that run with prev and curr, hook the previous group's tail onto the new front.

Decision · step 2 of 13Rewiring a List: Groups of 3 with a short tail
12345678currhead

From 1, count 3 ahead: 1, 2, 3 is a full group, ending before 4. Reverse it.

Open in the player →or start at step 2

What you will see

One block reverses at a time; its tail reattaches to the next block's head.

How rewiring a list works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(1)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Each node announces its value and what it points to; each step announces the pointer change ("node 3 now points to node 5").

Reduced motion: Pointer arrows redraw in place with a brief emphasis instead of animating the detach and reattach.

Taught by the same lesson

Rewiring a List covers these too, in the same run.