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

0

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
binary search
intervals
calendar booking
bisect
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
  • 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 Problems
Sample Answer
Requirements
  • Input: sorted schedule of [start, end) minutes, buffer b >= 0, new trip [s, e).
  • Valid if prev.end + b <= s and e + b <= next.start for 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...


Submit Your Answer
Markdown supported