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
Coding & Algorithms
Software Engineer
Flipkart
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Hard

0

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
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 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 Problems
Sample Answer
Requirements
  • Input: head of a singly linked list of stops and K >= 1.
  • Reverse each full block of K consecutive stops; a trailing block shorter than K stays 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....


Submit Your Answer
Markdown supported

Related Questions