Compute conflicts and minimum meeting rooms
Company: Apple
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates the ability to reason about interval overlaps and resource allocation, testing algorithmic thinking and efficient handling of time-interval data in scheduling contexts and belongs to the Coding & Algorithms domain.
Part 1: Can All Meetings Fit in One Room?
Constraints
- 0 <= n <= 10^5, where n is the number of intervals
- Each interval has exactly two integers: start and end
- For every interval, start < end
- Intervals are half-open: [start, end)
Examples
Input: [[0, 30], [5, 10], [15, 20]]
Expected Output: False
Explanation: The meeting [0, 30) overlaps with both [5, 10) and [15, 20), so one room is not enough.
Input: [[1, 3], [3, 5], [5, 8]]
Expected Output: True
Explanation: These meetings only touch at boundaries. Because the intervals are half-open, they do not overlap.
Hints
- Try sorting the meetings by their start time first.
- After sorting, it is enough to compare each meeting with the one that ends most recently before it.
Part 2: Minimum Number of Meeting Rooms
Constraints
- 0 <= n <= 10^5, where n is the number of intervals
- Each interval has exactly two integers: start and end
- For every interval, start < end
- Intervals are half-open: [start, end)
Examples
Input: [[0, 30], [5, 10], [15, 20]]
Expected Output: 2
Explanation: At most two meetings overlap at once, so two rooms are required.
Input: [[1, 3], [3, 5], [5, 8]]
Expected Output: 1
Explanation: Each meeting starts exactly when the previous one ends, so one room can be reused.
Hints
- If you process meetings in start-time order, you only need to know which scheduled meeting ends earliest.
- A min-heap of end times is a good way to reuse rooms as soon as they become free.