FastPrepFind Available Meeting Rooms

Find Available Meeting Rooms

Microsoft logoMicrosoft● MediumINTERNOA

Problem statement

There are m meeting rooms numbered 1 through m. Each existing booking is [room,startTime,endTime]. Find every room available for the whole requested interval [start,end).

Bookings use half-open intervals: a booking ending at start, or starting at end, does not overlap the request. Return the available room IDs in increasing order.

Function

availableRooms(m: int, bookings: int[][], start: int, end: int) → int[]

Examples

Example 1

m = 4bookings = [[1,3,5],[1,1,2],[2,2,6]]start = 5end = 10return = [1,3,4]

Room1 is free because both its meetings end by5. Room2 is occupied until6, which overlaps [5,10). Rooms3 and4 have no bookings. Return [1,3,4].

Constraints

  • 1 <= m <= 200000.
  • 1 <= bookings.length <= 200000.
  • Every booking contains exactly three integers [room,startTime,endTime].
  • Every booking integer, start, and end is between 1 and 10^9.
  • start < end.
  • Each booking has 1 <= room <= m and startTime < endTime.

More Microsoft problems

See Microsoft hiring insights
Saved
public int[] availableRooms(int m, int[][] bookings, int start, int end) {
    // Write your solution here.
}
Checking account…