Live Disjoint Online Intervals From a Stream of Driver Activity Minutes
Last updated: November 29, 2026
Quick Overview
A stream reports minute indices when a driver was seen online, in any order and with duplicates. Support add(minute) and intervals(), which returns the current list of disjoint, sorted, inclusive online intervals formed by merging consecutive minutes.
Uber
November 29, 20260
0
0 solved
A stream reports minute indices when a driver was seen online, in any order and with duplicates. Support add(minute) and intervals(), which returns the current list of disjoint, sorted, inclusive online intervals formed by merging consecutive minutes.
A streaming data structure problem in the style of Uber's onsite coding, based on reconstructing driver online sessions from activity pings for earnings and incentive eligibility. The interviewer wants logarithmic insertion with neighbor merging, not re-sorting the whole stream on every query.
What the Interviewer Expects
- Keeps interval starts in a sorted structure
- Finds the neighbor intervals with binary search
- Handles four cases: inside, extend left, extend right, bridge two intervals
- Ignores duplicates and minutes already covered
- Discusses balanced trees versus Python lists for insertion cost
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 also return the total online minutes in O(1)?
- What if pings mark the driver offline as well?
- How would you cap memory for a stream covering a whole year?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
API: add(m) with integer minutes, intervals() returning a list of [start, end]. Adds vastly outnumber queries in production, so each add should be about for k intervals plus insertio...
High-Level Design
Maintain parallel sorted lists starts and ends. For add(m), binary search for i = bisect_right(starts, m) - 1, the interval starting at or before m. If ends[i] >= m, the minute is already co...