Meeting Room Scheduler
Problem statement
Implement a scheduler for roomCount meeting rooms numbered from 0 to roomCount - 1.
Each row meetings[i] = [start, end] is a request for the half-open interval [start, end). Requests appear in nondecreasing start order and are processed in input order. Assign the lowest-numbered available room. If every room overlaps the request, reject it with -1.
Return an array whose ith value is the assigned room number or -1. A rejected request does not reserve a room.
Function
scheduleMeetings(roomCount: int, meetings: int[][]) → int[]Examples
Example 1
roomCount = 2meetings = [[0,10],[5,7],[10,12],[10,15]]return = [0,1,0,1]The first two requests occupy rooms 0 and 1. At time 10, both are free; input order gives the third request room 0 and the fourth room 1.
Example 2
roomCount = 1meetings = [[1,4],[2,3],[4,5]]return = [0,-1,0]The second request conflicts with [1,4). The room is available again exactly at time 4.
Example 3
roomCount = 2meetings = [[1,2],[1,2],[1,2]]return = [0,1,-1]Two simultaneous requests take both rooms, so the third request is rejected.
Constraints
1 <= roomCount <= 10^5.1 <= meetings.length <= 10^5.meetings[i].length == 2.0 <= start < end <= 10^9.- Meeting start times are nondecreasing.