Skip to content

Meeting Rooms III

HardHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.

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.

n = 2, meetings = [[0, 10], [1, 5], [2, 7], [3, 4]]  →  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.