The Data Stream as Disjoint Intervals interview question asks you to design a class that receives a stream of non-negative integers and summarizes the numbers seen so far as a list of disjoint intervals. For example, if you see 1, 2, and 3, they form the interval [1, 3]. If you then see 5, the intervals are [1, 3] and [5, 5]. This Data Stream as Disjoint Intervals coding problem is about real-time data aggregation.
Amazon and Google ask this to test your ability to choose the right data structure for efficient inserts and searches. A simple list would be O(N) to insert, making the overall process slow. Using an Ordered Set or a TreeMap allows you to find neighboring intervals in O(log N) and merge them in O(1). It evaluates your system design thinking within an algorithmic context.
This utilizes the Design, Binary Search, Ordered Set interview pattern.
Current Intervals: [1, 2], [4, 5].
Be comfortable with TreeMap (Java) or std::set/map (C++). Knowing how to use floorKey, ceilingKey, lower, and higher is essential for interval merging problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| My Calendar III | Hard | Solve | |
| My Calendar I | Medium | Solve | |
| Tweet Counts Per Frequency | Medium | Solve | |
| Count Integers in Intervals | Hard | Solve | |
| Range Module | Hard | Solve |