Meeting Rooms III

You are given an integer n. There are n rooms numbered from 0 to n - 1.

You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.

Meetings are allocated to rooms in the following manner:

  • Each meeting will take place in the unused room with the lowest number.
  • If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.
  • When a room becomes unused, meetings that have an earlier original start time should be given the room.

Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.

A half-closed interval [a, b) is the interval between a and b including a and not including b.

Example 1
0-------------------10
  1-------5
    2---------7
      3-4
Inputn = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
Output0
Both rooms 0 and 1 held 2 meetings, so room 0 is returned because it has the lowest number.
Example 2
1-------------------------------------20
  2---------------10
    3---5
      4---------9
          6---8
Inputn = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]
Output1
Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so room 1 is returned because it has the lowest number among the tied rooms.

Constraints

  • 1 <= n <= 100
  • 1 <= meetings.length <= 10^5
  • meetings[i].length == 2
  • 0 <= starti < endi <= 5 * 10^5
  • All the values of starti are unique.

Asked at 12 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate