ASAPUtils Logo ASAPUtils
Week 5

Reverse Nodes in k-Group

Reverse Nodes in k-Group through bounded reversal and four boundary pointers, with C++ and JavaScript implementations, reconnection proof, O(1) space, incomplete-group handling, traps, and an interactive group trace.

The problem

Reverse every complete consecutive group of k linked-list nodes in place, leaving a final group with fewer than k nodes unchanged.

1 -> 2 -> 3 -> 4 -> 5, k = 2 becomes 2 -> 1 -> 4 -> 3 -> 5

Related Problems