Shortest Route for a Rider Carrying Several Batched Orders
Last updated: November 29, 2026
Quick Overview
A rider must pick up k orders from their restaurants and drop each at its customer, with each pickup before its drop. Given a travel-time matrix between the rider and all 2k stops, return the minimum total travel time.
Zomato
November 29, 20260
0
0 solved
A rider must pick up k orders from their restaurants and drop each at its customer, with each pickup before its drop. Given a travel-time matrix between the rider and all 2k stops, return the minimum total travel time.
When Zomato batches orders onto one delivery partner, the stop sequence decides whether the last customer's food arrives hot. Onsite, this checks bitmask DP, precedence constraints and the judgement to say when exact search stops being viable.
What the Interviewer Expects
- Recognize a precedence-constrained shortest Hamiltonian path
- Model state as (visited mask, current stop)
- Enforce pickup-before-drop when choosing the next stop
- Give O(4^k * k^2) style complexity and its practical limit
- Suggest heuristics for larger k
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 minimize the latest delivery time instead of total travel time?
- How would you add a capacity limit on bags carried at once?
- Restaurants have ready times, so the rider may wait. How does the state change?
- What would you do for k = 10 inside a 50 ms assignment budget?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Node 0 is the rider's location, nodes 1..k are pickups, k+1..2k are drops, and drop k+i requires pickup i first. dist is a full travel-time matrix (already computed from the road graph). The rou...
High-Level Design
This is a shortest Hamiltonian path with precedence. Let dp(mask, last) be the minimum remaining time after visiting the stops in mask and standing at last. From a state we may visit any unvisit...