Insert a Scheduled Ride Into a Driver Calendar With Buffers
Last updated: November 29, 2026
Quick Overview
A driver has a sorted list of non-overlapping reserved trips [start, end) and needs at least b minutes between consecutive trips; given a new reservation, return the updated schedule if it fits or None if it conflicts.
Uber
November 29, 20260
0
0 solved
A driver has a sorted list of non-overlapping reserved trips [start, end) and needs at least b minutes between consecutive trips; given a new reservation, return the updated schedule if it fits or None if it conflicts.
Uber Reserve lets riders book trips in advance, and dispatch must check a new booking against a driver's commitments, including repositioning time between trips. The screen checks a binary search for the insertion point and precise neighbor checks rather than a full rescan.
What the Interviewer Expects
- Use binary search to find the insertion point in O(log n)
- Check only the immediate predecessor and successor
- Apply the buffer correctly on both sides
- Return a new list instead of mutating the caller's data, or say so
- Discuss how a balanced tree would support many inserts
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
- What if the buffer depends on the distance between dropoff and next pickup?
- How would you support thousands of inserts and deletes per driver efficiently?
- Return the nearest feasible start time if the requested slot conflicts
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: sorted
scheduleof[start, end)minutes, bufferb >= 0, new trip[s, e). - Valid if
prev.end + b <= sande + b <= next.startfor the neighbors around the insertion point. - Outpu...
High-Level Design
Because the schedule is sorted and non-overlapping, ends are also sorted. bisect_left on start times gives the index i where the new trip would go. Only schedule[i - 1] and schedule[i] can con...