Insert a Do Not Disturb Window Into a Sorted Notification Schedule
Last updated: November 29, 2026
Quick Overview
A user's quiet hours are stored as a sorted list of non-overlapping [start, end] minute intervals. Insert a new quiet window and return the list still sorted and non-overlapping, merging anything it touches.
Meta
November 29, 20260
0
0 solved
A user's quiet hours are stored as a sorted list of non-overlapping [start, end] minute intervals. Insert a new quiet window and return the list still sorted and non-overlapping, merging anything it touches.
A classic interval warm-up in the style of Meta's phone screen, framed around the notification platform that must respect quiet hours before it sends a push. The interviewer checks that you exploit the existing sorted order for a linear pass instead of re-sorting, and that you handle touching endpoints deliberately.
What the Interviewer Expects
- Asks whether touching intervals like [1,3] and [3,5] should merge
- Uses the sorted input to get O(n) instead of sorting again
- Splits the pass into three clean phases: before, overlapping, after
- Returns a new list rather than mutating in confusing ways
- Tests insertion at the front, the back, and spanning everything
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 support deleting a quiet window, splitting an interval if needed?
- If inserts are frequent, what data structure gives O(log n) per insert?
- How would you handle windows that wrap past midnight?
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: windows, a list of [start, end] sorted by start with no overlaps, and new, one [start, end]. Output: a sorted, non-overlapping list that covers exactly the union. Confirm that touching ...
High-Level Design
Because the list is already sorted and disjoint, every existing window falls into one of three groups relative to new: entirely before it (end < new.start), overlapping it, or entirely after it (`...