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:
- Each meeting goes to the free room with the lowest number.
- 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.
- 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]] → 0Room 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 <= 1001 <= meetings.length <= 10^50 <= start_i < end_i <= 5 * 10^5- All values of
start_iare unique.