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.
Rewiring a List: Groups of 3 with a short tail
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)
Before this
Taught by the same lesson
Rewiring a List covers these too, in the same run.