This question evaluates a candidate's competence in scheduling and resource-allocation algorithms, focusing on simulation of interval-based bookings, tie-breaking logic, and tracking per-resource assignment counts.
You manage n meeting rooms labeled 0..n-1 and receive a list of meetings. Each meeting is an interval [start, end) with start < end.
Process meetings in increasing order of start time (if not already sorted).
Room assignment rules
start
, assign the meeting to the free room with the
smallest room id
.
start
, the meeting is
delayed
until the earliest time when some room becomes free. It must keep the
same duration
duration = end - start
, and it is assigned to the room that becomes free earliest (break ties by smallest room id).
t
, it ends at
t + duration
.
Let count[i] be the number of meetings assigned to room i. Return the room id with the maximum count[i]. If there is a tie, return the smallest room id among the tied rooms.
Input
n
: integer
meetings
: list of pairs
[start, end)
Output
Constraints (typical for this problem)
1 ≤ n ≤ 10^5
1 ≤ len(meetings) ≤ 2*10^5
Notes