Meeting Rooms III - Problem
You are given an integer n. There are n rooms numbered from 0 to n - 1.
You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.
Meetings are allocated to rooms in the following manner:
- Each meeting will take place in the unused room with the lowest number.
- If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.
- When a room becomes unused, meetings that have an earlier original start time should be given the room.
Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.
Input & Output
Example 1 — Basic Case
$
Input:
n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
›
Output:
0
💡 Note:
Room 0: gets [0,10], [2,7] (delayed to [10,17]), [3,4] (delayed to [17,18]) = 3 meetings. Room 1: gets [1,5] = 1 meeting. Room 0 has most meetings.
Example 2 — Equal Distribution
$
Input:
n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]
›
Output:
0
💡 Note:
Room 0: [1,20], [6,8] (delayed to [20,22]) = 2 meetings. Room 1: [2,10], [4,9] (delayed to [10,15]) = 2 meetings. Room 2: [3,5] = 1 meeting. Tie between rooms 0 and 1, return lowest number 0.
Example 3 — Single Room
$
Input:
n = 1, meetings = [[1,5],[2,3],[4,6]]
›
Output:
0
💡 Note:
Only room 0: gets [1,5], [2,3] (delayed to [5,6]), [4,6] (delayed to [6,8]) = 3 meetings. Room 0 is the only choice.
Constraints
- 1 ≤ n ≤ 100
- 1 ≤ meetings.length ≤ 105
- meetings[i].length == 2
- 0 ≤ starti < endi ≤ 5 × 105
- All the values of starti are unique
Visualization
Tap to expand
Understanding the Visualization
1
Input
n=2 rooms, meetings=[[0,10],[1,5],[2,7],[3,4]]
2
Process
Schedule to lowest available room, delay if all busy
3
Output
Room 0 holds most meetings (3), return 0
Key Takeaway
🎯 Key Insight: Use priority queues to efficiently track available and occupied rooms, avoiding O(n) scans for each meeting
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code