Problem
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:
-
If one or more rooms are free at
start
, assign the meeting to the
free room with the smallest index
.
-
If no rooms are free at
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.
Task
Return the index of the room that hosted the most meetings. If there is a tie, return the smallest index.
Input/Output
-
Input:
n
(int),
meetings
(list of
[start,end]
)
-
Output: an integer room index
Constraints (reasonable interview assumptions)
-
1 <= n <= 10^5
-
1 <= len(meetings) <= 10^5
-
Times fit in 32-bit signed integer; waiting can increase end times beyond original but still fits in 64-bit.