A building has n meeting rooms, labeled 0 through n - 1. Implement mostBooked(n, meetings), where meetings holds m entries and meetings[i] = [start_i, end_i] gives the start and end times at which meeting i was originally planned.
Rooms are assigned according to these rules:
start_i.Return the index of the room in which the largest number of meetings took place. If several rooms tie for that count, return the lowest index among them.
Example 1:
Input: n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
Output: 0
Explanation: Meeting [0,10] takes room 0 and [1,5] takes room 1. Meeting [2,7] must wait until room 1 frees at time 5, running over [5,10]. Meeting [3,4] waits until time 10, when both rooms free simultaneously, so it goes to room 0 over [10,11]. Each room hosts two meetings, and the tie goes to room 0.
n = 2 meetings = [[0,10], [1, 5], [2, 7], [3, 4]]
0
Two rooms (0 and 1) and four planned meetings. Meetings are handled in order of planned start time.
Example 2:
Input: n = 3, meetings = [[0,10],[1,9],[2,8],[3,7],[4,6]]
Output: 1
Explanation: The first three meetings take rooms 0, 1 and 2. Meeting [3,7] finds every room busy and waits for room 2, which frees at time 8, so it runs [8,12]. Meeting [4,6] then waits for room 1, which frees at time 9, and runs [9,11]. Room 0 hosted one meeting while rooms 1 and 2 hosted two each, so the tie is broken toward room 1.
Example 3:
Input: n = 4, meetings = [[0,2],[3,5],[6,8]]
Output: 0
Explanation: Every meeting starts when room 0 is already free, so room 0 hosts all three meetings and no other room is used.
Constraints:
m is the length of meetingsstart_i is distinct.n = 2 meetings = [[0,10], [1, 5], [2, 7], [3, 4]]
0
Two rooms (0 and 1) and four planned meetings. Meetings are handled in order of planned start time.