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

0

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
Intervals
Linear Scan
Merging
Arrays
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
  • 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 Problems
Sample 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:

  1. Copy every slot whose end is strictly before the new start; they are untouched.
  2. While a slot starts at or before the new end, it overlaps, so widen the new slot t...

Submit Your Answer
Markdown supported