Assign Ride Requests to the Best Free Driver Over Time
Last updated: November 29, 2026
Quick Overview
Drivers have a priority score (lower is better) and index. Request j arrives at second j and takes duration[j] seconds. Assign each request to the free driver with the lowest (priority, index); if none is free, wait for the earliest driver to finish, breaking ties the same way. Return the driver index for each request.
Uber
November 29, 20260
0
0 solved
Drivers have a priority score (lower is better) and index. Request j arrives at second j and takes duration[j] seconds. Assign each request to the free driver with the lowest (priority, index); if none is free, wait for the earliest driver to finish, breaking ties the same way. Return the driver index for each request.
An Uber onsite simulation problem that echoes dispatch logic. It checks whether you can model time correctly with two heaps and avoid stepping one second at a time when everyone is busy.
What the Interviewer Expects
- Keeps a heap of free drivers keyed by (priority, index)
- Keeps a heap of busy drivers keyed by (free_time, priority, index)
- Releases all drivers whose free_time is at or before the current time
- Jumps time forward to the earliest finish when no driver is free
- States O((n + m) log n) time
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 add a distance term so the nearest driver is preferred?
- What if requests can be cancelled before assignment?
- How would you scale this across many cities with a dispatch service?
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: list
priorityfor n drivers, listdurationfor m requests. - Request j becomes available at time j and requests are served in order.
- Output: list of driver indices of length m....
High-Level Design
Two heaps model the state. free holds (priority, index) for idle drivers. busy holds (free_at, priority, index). For request j at time t = max(j, current), first move every busy driver with ...