AlgoScope

Reverse in Groups of k

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

Linked list algorithms, algorithm, intermediate
Group 1, 2, 3.12345678currhead
Group 1, 2, 3.12345678currhead

Rewiring a List: Groups of 3 with a short tail

Decision, step 2 of 13

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

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)

Taught by the same lesson

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