This question evaluates scheduling and event-simulation skills, including time-ordered processing, resource allocation with tie-breaking, and efficient tracking of room availability and usage counts using appropriate data structures.
You are given n meeting rooms labeled 0..n-1 and a list of meetings meetings, where each meeting is [start, end] with start < end. Meetings are processed in increasing order of start time.
Assign each meeting to a room using these rules:
start
, assign the meeting to the
free room with the smallest index
.
start
, the meeting must
wait
until a room becomes free. It is then scheduled in the room that becomes available
earliest
(break ties by smallest room index). If it waits, its
duration stays the same
, so if the original duration is
end - start
and the room becomes free at time
t
, the meeting runs on
[t, t + (end - start)]
.
Each time a meeting is assigned to a room (even after waiting), that room’s meeting count increases by 1.
Return the index of the room that hosted the most meetings. If there is a tie, return the smallest index.
n
(int),
meetings
(list of
[start,end]
)
1 <= n <= 10^5
1 <= len(meetings) <= 10^5