Skip to content
Decoder

Meeting Rooms III

Hard

Problem

There are n rooms numbered 0 to n - 1. meetings[i] = [start_i, end_i] describes a meeting over the half-open time range [start, end). All start times are different. Meetings are assigned like this:

1. Each meeting goes to the free room with the lowest number. 2. If no room is free, the meeting is delayed until a room frees up, keeping its original duration. If several meetings are waiting, the one with the earlier original start goes first. 3. When a room frees up, the waiting meeting takes it; if several rooms free up at the same time, it takes the lowest-numbered one.

Return the room that held the most meetings. On a tie, return the lowest room number.

Example 1

Input
n = 2, meetings = [[0, 10], [1, 5], [2, 7], [3, 4]]
Output
0

Room 0 takes [0, 10), room 1 takes [1, 5). [2, 7) waits for room 1 and runs [5, 10). [3, 4) waits and runs [10, 11) in room 0. Both rooms hold 2 meetings, so the answer is 0.

Constraints

  • 1 <= n <= 100
  • 1 <= meetings.length <= 10^5
  • 0 <= start_i < end_i <= 5 * 10^5
  • All values of start_i are unique.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.