Book Delivery Time Windows Without Double Booking a Driver
Last updated: November 29, 2026
Quick Overview
A driver's schedule accepts half-open delivery windows [start, end). Implement book(start, end) that returns True and records the window if it does not overlap any booked window, and returns False otherwise.
Amazon
November 29, 20260
0
0 solved
A driver's schedule accepts half-open delivery windows [start, end). Implement book(start, end) that returns True and records the window if it does not overlap any booked window, and returns False otherwise.
This fits Amazon Flex and delivery scheduling, and Amazon technical screens use it to see whether you reach for an ordered structure instead of scanning every booking. Interviewers expect you to compare naive O(n) checks with an ordered-set approach.
What the Interviewer Expects
- Define overlap for half-open intervals precisely
- Keep bookings sorted by start
- Check only the neighbors around the insertion point
- Discuss the O(n) list insertion cost and a balanced BST or sorted container alternative
- Test boundaries where one window ends exactly when another starts
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 allow up to two overlapping bookings but reject a third?
- How would you cancel a booking?
- What structure would you use in Java or C++ to get O(log n) inserts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Calls book(start, end) with start < end. Windows [a, b) and [c, d) overlap when a < d and c < b. Touching windows like [10, 20) and [20, 30) do not overlap. Return True and store, or False and leave s...
High-Level Design
Keep two parallel sorted lists of starts and ends (bookings never overlap, so sorting by start also sorts by end). For a new window, binary search the insertion index i among starts. Only two bookings...