Insert a New Delivery Slot Into a Sorted Slot Calendar
Last updated: November 29, 2026
Quick Overview
Given a sorted list of non-overlapping delivery time slots and a new slot, insert the new slot and merge where necessary so the calendar stays sorted and non-overlapping.
Amazon
November 29, 20260
0
0 solved
Given a sorted list of non-overlapping delivery time slots and a new slot, insert the new slot and merge where necessary so the calendar stays sorted and non-overlapping.
An Amazon technical screen question tied to the delivery window picker shown at checkout. The interviewer expects a linear three-phase scan that uses the existing sorted order, rather than appending and re-sorting.
What the Interviewer Expects
- Use the existing sort order instead of re-sorting
- Copy slots ending before the new slot
- Absorb every slot that overlaps the new one
- Copy the remaining slots unchanged
- Achieve O(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 do this in O(log n) to find the position plus output cost?
- What if overlapping slots should be rejected instead of merged?
- How would you support deleting a slot as well?
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: slots, a list of [start, end] sorted by start and pairwise non-overlapping; and new, a [start, end] pair. Output: the updated sorted, non-overlapping list. Touching slots merge....
High-Level Design
Three phases over one pointer:
- Copy every slot whose end is strictly before the new start; they are untouched.
- While a slot starts at or before the new end, it overlaps, so widen the new slot t...