Find the meeting room that hosts the most meetings

Write codeMedium30 minMeta style

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 to n - 1.
  • meetings: a list of 1 to 10,000 pairs [start, end] of integers between 0 and 1,000,000,000, with start less than end. A meeting runs from start up to, but not including, end.
  • Returns a room number.

Rules:

  • Handle the meetings in order of start. Meetings with the same start keep their order from the list.
  • Before placing a meeting, every room whose current meeting ends at or before that meeting's start is 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]]) -> int
Example 1
Inputmost_booked_room(2, [[0, 10], [1, 5], [2, 7], [3, 4]])
Output0
Example 2
Inputmost_booked_room(2, [[5, 6], [0, 10], [0, 1]])
Output1