.next will be linked to the new chunk head (kth).
curr.next = prev inside the group.
kth.next), used as initial prev value to maintain onward connection.
Step 1: Look Ahead (Check k nodes)
We initialize a sentinel dummy node pointing to the head. We then advance kth by k steps from groupPrev to see if a complete group exists.
Verify at least k nodes remain. If not, finish early.
Standard in-place reversal of arrows using curr and prev.
Connect previous tail to new head, and advance groupPrev.
Every node is visited at most 2 times: once by the kth lookahead counter to validate group size, and once by the pointer reversal step (curr.next = prev). Total operations = 2N ∈ O(N).
Strictly in-place pointer manipulation. Only 5 pointer variables (dummy, groupPrev, kth, curr, prev, temp) are maintained without recursion stacks or external list nodes.
Problem Constraints & Edge Cases Handled
k, the remaining nodes must keep their original order.
node.next) are redirected.
O(1) memory. Array copying or converting to Python list is forbidden.