Meeting Rooms III - Problem
Imagine you're managing a busy conference center with n meeting rooms numbered from 0 to n-1. Throughout the day, you receive a list of meeting requests, each with a specific start and end time.
You are given a 2D integer array meetings where meetings[i] = [starti, endi] represents a meeting that needs the time interval [starti, endi) (half-closed interval - includes start time but excludes end time).
Room Allocation Rules:
- ๐ข Each meeting gets assigned to the lowest-numbered available room
- โฐ If no rooms are free, the meeting is delayed until a room becomes available (keeping the same duration)
- ๐ When multiple meetings are waiting, priority goes to the meeting with the earliest original start time
Goal: Return the room number that hosted the most meetings. If there's a tie, return the lowest-numbered room.
Input & Output
example_1.py โ Basic Room Assignment
$
Input:
n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
โบ
Output:
0
๐ก Note:
Room 0: meetings [0,10), [1,5) (delayed to [10,15)), [2,7) (delayed to [15,20)), [3,4) (delayed to [20,21)) - 4 meetings. Room 1: no meetings. Room 0 has the most meetings.
example_2.py โ Multiple Rooms Used
$
Input:
n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]
โบ
Output:
1
๐ก Note:
Room 0 gets [1,20). Room 1 gets [2,10), [4,9) (delayed to [10,15)), [6,8) (delayed to [15,17)) - 3 meetings. Room 2 gets [3,5). Room 1 has the most meetings.
example_3.py โ Tie Breaking
$
Input:
n = 4, meetings = [[18,19],[3,12],[17,19],[2,13]]
โบ
Output:
0
๐ก Note:
After sorting by start time: [2,13), [3,12), [17,19), [18,19). Each room gets 1 meeting, so return room 0 (lowest number).
Constraints
- 1 โค n โค 100
- 1 โค meetings.length โค 105
- meetings[i].length == 2
- 0 โค starti < endi โค 5 ร 105
- All start times are unique
Visualization
Tap to expand
Understanding the Visualization
1
Sort Meetings
Process meetings in chronological order by start time
2
Track Availability
Use min-heap to always get the lowest available room number
3
Handle Conflicts
When all rooms busy, delay meeting using earliest finishing room
4
Count and Compare
Track meetings per room, return room with maximum count
Key Takeaway
๐ฏ Key Insight: Priority queues provide O(log n) efficient room management, making this scheduling problem tractable even for large inputs by maintaining optimal room assignment order.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code