Insert a Do-Not-Disturb Window Into a Sorted Lark Schedule

Last updated: November 29, 2026

Quick Overview

A Lark user's do-not-disturb windows are stored as a sorted list of non-overlapping closed intervals; insert a new window and return the list still sorted, merging any windows it overlaps or touches.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A Lark user's do-not-disturb windows are stored as a sorted list of non-overlapping closed intervals; insert a new window and return the list still sorted, merging any windows it overlaps or touches.

Lark (Feishu) lets users block notification windows, and the client must keep that list normalized after every edit. This interval question in ByteDance's screening style checks a single linear pass that uses the existing sort order instead of re-sorting and re-merging everything.

What the Interviewer Expects
  • Use the fact that the input is already sorted and disjoint
  • Split the pass into before, overlapping, and after phases
  • Merge touching windows because intervals are closed
  • Achieve O(n) time without sorting
  • Leave the input list unmodified
Key Topics to Cover
intervals
merging
linear scan
sorted input
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
  • Support removing a window, which may split an existing one in two.
  • Thousands of inserts per user: which structure keeps each insert O(log n)?
  • Windows recur daily and can cross midnight: how do you represent them?
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: a list of (start, end) tuples with start <= end, sorted by start, no two overlapping or touching, and a new window (start, end). Windows are closed, so (1, 2) and (2, 3) touch and must merge. O...

High-Level Design

Three phases in one pass. First copy every window that ends strictly before the new start, since it cannot interact. Then absorb every window whose start is at most the current merged end, widening th...


Submit Your Answer
Markdown supported