Find Minimum Rooms Needed
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of interval scheduling and conflict detection in time ranges, along with algorithmic reasoning and appropriate data structure use for managing concurrent events and resource allocation.
Part 1: Minimum Number of Meeting Rooms
Constraints
- 0 <= n <= 200000, where n is the number of meetings
- -10^9 <= start < end <= 10^9
- Intervals are half-open: [start, end), so end == next_start does not overlap
Examples
Input: [[0, 30], [5, 10], [15, 20]]
Expected Output: 2
Explanation: The meeting [0, 30) overlaps with both later meetings, so two rooms are needed.
Input: [[1, 3], [3, 5], [5, 7]]
Expected Output: 1
Explanation: Because intervals are half-open, each meeting starts exactly when the previous one ends, so one room is enough.
Input: []
Expected Output: 0
Explanation: No meetings means no rooms are required.
Input: [[7, 10], [2, 4]]
Expected Output: 1
Explanation: These meetings do not overlap, even though the input is unsorted.
Input: [[1, 5], [2, 6], [4, 8], [5, 7]]
Expected Output: 3
Explanation: At time 4, three meetings are active: [1, 5), [2, 6), and [4, 8).
Hints
- Sort meetings by start time. As you scan from left to right, keep track of meetings that are still in progress.