Reverse Packet Batches of Size K in a Linked Send Buffer

Last updated: November 29, 2026

Quick Overview

A network driver keeps outgoing packets in a singly linked list. Reverse the nodes in each consecutive batch of k packets in place, leaving a final partial batch in its original order, and return the new head.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A network driver keeps outgoing packets in a singly linked list. Reverse the nodes in each consecutive batch of k packets in place, leaving a final partial batch in its original order, and return the new head.

This appears in Microsoft onsites for systems leaning teams such as Windows networking, where pointer correctness under pressure is the main signal. The interviewer watches how you structure group boundaries and whether you test partial final groups.

What the Interviewer Expects
  • Check that k nodes remain before reversing a group
  • Reverse a group by linking its first node to the node after the group
  • Reconnect the previous group's tail to the new group head
  • Use O(1) extra space
  • Test k = 1, k equal to the length, and a partial tail group
Key Topics to Cover
linked lists
in-place reversal
pointer manipulation
dummy node
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you also reverse the final partial batch?
  • Do it recursively and compare stack usage.
  • What if batches alternate between reversed and not reversed?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: head of a singly linked list and a positive integer k.
  • Reverse each full block of k nodes; a last block with fewer than k nodes stays as is.
  • Relink nodes, do not swap values.
  • O(1) extra...
High-Level Design

Use a dummy before the head and a pointer group_prev to the node just before the current group. For each group:

  1. Walk k steps from group_prev to find kth. If we fall off, we are done.
  2. Reme...

Submit Your Answer
Markdown supported