Reverse Nodes in k-Group

Asked atAgoda
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Use a dummy head and group predecessor
  2. 02Find the kth node before reversing
  3. 03Leave an incomplete group intact
  4. 04Reverse nodes within the group boundary
  5. 05Reconnect predecessor, tail, and next group

Reference answer

Then expect these follow-ups

  • How would you write the recursive form?

    Tests: follow-up reasoning

  • Why does prev begin at groupNext?

    Tests: correctness reasoning

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question