Implement assign_meeting_rooms(intervals). Each interval is [start, end), so a room used by a meeting ending at time t is available to another meeting starting at t.
Return one flat integer list [room_count, room_for_meeting_0, room_for_meeting_1, ...]. The first value is the minimum number of rooms required, and each following value is the nonnegative room ID assigned to the interval at that original input index.
The output must be deterministic:
-
Process meetings by increasing start time, then increasing end time, then original index.
-
Reuse the smallest room ID that is free at the meeting's start.
-
If no room is free, allocate the next unused room ID.
Every interval has start < end.
Discussion Extensions
-
If only the minimum room count were required, how would a sweep line solve the problem?
-
What changes if intervals arrive as a stream and cannot first be globally sorted?