Find the meeting room that hosts the most meetings
Your task
An office books its meeting rooms with a simple rule: take the lowest-numbered free room, and if every room is busy, wait for the first one to free up.
Write most_booked_room(n, meetings) that returns the room that held the most meetings.
Input and output:
n: the number of rooms, from 1 to 100. Rooms are numbered 0 ton - 1.meetings: a list of 1 to 10,000 pairs[start, end]of integers between 0 and 1,000,000,000, withstartless thanend. A meeting runs fromstartup to, but not including,end.- Returns a room number.
Rules:
- Handle the meetings in order of
start. Meetings with the samestartkeep their order from the list. - Before placing a meeting, every room whose current meeting ends at or before that meeting's
startis free again. - If any room is free, the meeting takes the lowest-numbered free room.
- If no room is free, the meeting waits for the room that frees up first, or the lowest-numbered of those that free up at the same moment. It starts at that moment and keeps its original length.
- A delayed meeting does not change the order in which the remaining meetings are handled.
- Return the room that held the most meetings. If rooms tie, return the lowest-numbered one.
Examples
most_booked_room(n: int, meetings: list[list[int]]) -> intExample 1
Input
most_booked_room(2, [[0, 10], [1, 5], [2, 7], [3, 4]])Output
0Example 2
Input
most_booked_room(2, [[5, 6], [0, 10], [0, 1]])Output
1