Reverse Delivery Stops in Groups of K on a Route List
Last updated: November 29, 2026
Quick Overview
A delivery route is a singly linked list of stops. Reverse the stops in consecutive groups of K, leaving a final group with fewer than K stops in its original order, using O(1) extra space.
Flipkart
November 29, 20260
0
0 solved
A delivery route is a singly linked list of stops. Reverse the stops in consecutive groups of K, leaving a final group with fewer than K stops in its original order, using O(1) extra space.
A pointer manipulation problem that Flipkart uses in technical screens to separate careful coders from pattern matchers, framed as re sequencing batches of stops on a rider's route. The interviewer watches for correct reconnection between groups and an untouched short tail.
What the Interviewer Expects
- Check that K nodes remain before reversing a group
- Reverse a group in place with three pointers
- Reconnect the previous group's tail to the new group head
- Use a dummy head to avoid special casing the first group
- State O(n) time and O(1) space
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 short group?
- Can you write it recursively, and what does that cost in stack space?
- How would you reverse alternate groups of K only?
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 of stops and
K >= 1. - Reverse each full block of
Kconsecutive stops; a trailing block shorter thanKstays as is. - Rewire pointers, do not copy values, a...
High-Level Design
Use a dummy node before the head so every group has a predecessor, group_prev. For each round: walk K steps from group_prev to find the group's last node kth; if the list ends first, stop....