Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

head =
k =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Reverse nodes in-place group by group using pointer rewiring.

Approach

For each group:

  1. Find the k-th node after groupPrev. If fewer than k nodes remain, stop.
  2. Reverse the nodes in the group, pointing them toward groupNext.
  3. Reconnect groupPrev to the new head (k-th), then move groupPrev to the old head.

Why it works

Each group is reversed independently while maintaining correct connections to the rest of the list.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Reverse nodes in-place group by group using pointer rewiring.

Approach

For each group:

  1. Find the k-th node after groupPrev. If fewer than k nodes remain, stop.
  2. Reverse the nodes in the group, pointing them toward groupNext.
  3. Reconnect groupPrev to the new head (k-th), then move groupPrev to the old head.

Why it works

Each group is reversed independently while maintaining correct connections to the rest of the list.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)