Schedule Non-Overlapping Meetings Efficiently
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates understanding of interval scheduling and overlap detection, proficiency in selecting efficient data structures for dynamic ordered intervals, and the ability to reason about algorithmic time and space complexity.
Constraints
- 1 <= len(operations) <= 200000
- -10^9 <= timestamp values <= 10^9
- For every book operation, start < end
- get_meetings must return meetings sorted by start time
Examples
Input: [('book', 10, 20), ('book', 20, 30), ('book', 15, 25), ('book', 5, 10), ('remove_before', 20), ('get_meetings',)]
Expected Output: [True, True, False, True, 2, [(20, 30)]]
Explanation: [10,20) and [20,30) can both be booked. [15,25) overlaps existing meetings, so it is rejected. [5,10) is adjacent to [10,20) and is allowed. Removing meetings ending at or before 20 removes [5,10) and [10,20).
Input: [('get_meetings',), ('remove_before', -10), ('book', -5, -1), ('book', -1, 2), ('get_meetings',)]
Expected Output: [[], 0, True, True, [(-5, -1), (-1, 2)]]
Explanation: Initially the schedule is empty. Removing before -10 removes nothing. Both negative/adjacent meetings can be booked.
Input: []
Expected Output: []
Explanation: No operations means no results.
Input: [('book', 1, 4), ('book', 6, 8), ('book', 4, 6), ('book', 2, 3), ('remove_before', 6), ('book', 0, 1), ('get_meetings',)]
Expected Output: [True, True, True, False, 2, True, [(0, 1), (6, 8)]]
Explanation: [1,4), [4,6), and [6,8) are all valid because they only touch at endpoints. [2,3) overlaps [1,4), so it is rejected. Removing before 6 deletes [1,4) and [4,6).
Hints
- If meetings are kept sorted by start time and never overlap, then their end times are also strictly increasing.
- Think about a data structure that can quickly split meetings by start time for booking, and also cut off an entire prefix of meetings whose end <= time.