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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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:
- Walk k steps from
group_prevto findkth. If we fall off, we are done. - Reme...