Reverse Every Batch of K Deliveries in a Courier Route List

Last updated: November 29, 2026

Quick Overview

A courier's deliveries form a singly linked list. Reverse the nodes in each consecutive batch of k, leaving a final batch shorter than k in its original order, and return the new head. Only pointers may change, not values.

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

0

0

0 solved


A courier's deliveries form a singly linked list. Reverse the nodes in each consecutive batch of k, leaving a final batch shorter than k in its original order, and return the new head. Only pointers may change, not values.

A pointer-heavy Uber onsite problem framed around batched Eats deliveries. The interviewer is checking that you can reverse segments in place, reconnect them correctly, and leave the tail intact, all in O(1) extra space.

What the Interviewer Expects
  • Checks that k nodes remain before reversing a batch
  • Reverses each batch in place
  • Reconnects the previous batch's tail to the new batch head
  • Leaves a short final batch untouched
  • Uses a dummy head to simplify the first batch
Key Topics to Cover
Linked lists
In-place reversal
Dummy node
Pointer manipulation
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 reverse the final short batch too?
  • How would you do this recursively and what is the space cost?
  • What if batches have varying sizes given by a list?
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 and k >= 1. Output: new head. Node values must not be swapped (each node carries a delivery object). O(1) extra space....

High-Level Design

Keep group_prev, the node just before the current batch (starting with a dummy). Walk k steps from it to find the batch's last node kth; if fewer than k remain, stop. Remember `group_next = kth.ne...


Submit Your Answer
Markdown supported