Find Any Available Meeting Room
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's competence in handling interval-based scheduling problems, specifically managing interval data and performing efficient searches within sorted bookings to detect potential overlaps.
Constraints
- 0 <= len(rooms) <= 10^5
- 0 <= total number of existing bookings across all rooms <= 2 * 10^5
- Each booking interval satisfies start < end
- Each room's bookings are sorted by start time and do not overlap
- -10^9 <= start < end <= 10^9 for all times
Examples
Input: ([[[1, 3], [5, 7]], [[2, 4], [8, 10]]], [3, 5])
Expected Output: 0
Explanation: In room 0, [3, 5) fits exactly between [1, 3) and [5, 7) because touching endpoints is allowed.
Input: ([[[1, 2], [4, 6]], [], [[0, 10]]], [2, 4])
Expected Output: 0
Explanation: The new meeting fits exactly in the gap of room 0. Although room 1 is also empty, the first valid room index is 0.
Input: ([[[1, 4]], [], [[0, 10]]], [2, 3])
Expected Output: 1
Explanation: Room 0 overlaps with [1, 4). Room 1 has no bookings, so it is the first valid room.
Input: ([[[1, 5]], [[5, 8]]], [2, 3])
Expected Output: 1
Explanation: Room 0 overlaps with [1, 5). In room 1, the meeting ends exactly when the existing booking starts, so it fits.
Input: ([[[1, 3], [6, 9]], [[0, 2], [3, 5]]], [2, 6])
Expected Output: -1
Explanation: The new meeting overlaps an existing booking in both rooms, so no room can hold it.
Input: ([], [1, 2])
Expected Output: -1
Explanation: There are no rooms at all.
Input: ([[[-5, -3], [0, 2]], [[-1, 1]]], [-3, 0])
Expected Output: 0
Explanation: In room 0, the meeting touches the end of the first booking and the start of the second booking, which is allowed for half-open intervals.
Hints
- For one room, think about where the new interval would be inserted if you kept the bookings sorted by start time.
- After finding that insertion position with binary search, you only need to check the neighboring intervals, not every interval in the room.