FastPrepFree Time for Every Meeting Room

Free Time for Every Meeting Room

Scale AI logoScale AI● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

You are given the busy schedule of roomCount meeting rooms. Room identifiers are the integers 0 through roomCount - 1. Each row of bookings is [room, start, end] and makes that room busy during the half-open interval [start, end).

Find every maximal positive-length interval when each room is free within the half-open planning window [windowStart, windowEnd).

  • Bookings may overlap, repeat, or appear in any order. A room is busy whenever at least one of its bookings covers the time.
  • Touching busy intervals form one continuous busy block.
  • Include free time before a room's first booking and after its last booking when it lies in the planning window.
  • A room with no bookings is free throughout the entire window. A room busy throughout the window contributes no row.

Return an int[][] whose rows are [room, freeStart, freeEnd], ordered by room identifier and then by interval start. Every booking lies entirely within the planning window.

Function

freeRoomIntervals(roomCount: int, bookings: int[][], windowStart: int, windowEnd: int) → int[][]

Examples

Example 1

roomCount = 2bookings = [[0,2,4],[0,3,6],[1,0,2],[1,5,10]]windowStart = 0windowEnd = 10return = [[0,0,2],[0,6,10],[1,2,5]]

Room 0 has a merged busy block [2,6). Room 1 is busy in [0,2) and [5,10). The returned rows are exactly the remaining portions of the window.

Example 2

roomCount = 3bookings = [[0,0,5],[0,5,10],[1,2,7],[1,3,4]]windowStart = 0windowEnd = 10return = [[1,0,2],[1,7,10],[2,0,10]]

Room 0 has no free time because touching bookings cover the window. Room 1 has one nested booking that changes no busy coverage. Room 2 is free for the whole window.

Example 3

roomCount = 1bookings = []windowStart = 5windowEnd = 8return = [[0,5,8]]

With no bookings, the room is free throughout the planning window.

Example 4

roomCount = 1bookings = [[0,1,9]]windowStart = 1windowEnd = 9return = []

The single booking covers the entire planning window, so there are no free intervals.

Constraints

  • 1 <= roomCount <= 10000.
  • 0 <= bookings.length <= 100000.
  • Each booking has exactly three integers and satisfies 0 <= room < roomCount.
  • 0 <= windowStart < windowEnd <= 1000000000.
  • Each booking satisfies windowStart <= start < end <= windowEnd.

More Scale AI problems

See Scale AI hiring insights
public int[][] freeRoomIntervals(int roomCount, int[][] bookings, int windowStart, int windowEnd) {
    // Write your solution here
}
roomCount2
bookings[[0,2,4],[0,3,6],[1,0,2],[1,5,10]]
windowStart0
windowEnd10
expected[[0,0,2],[0,6,10],[1,2,5]]
Checking account…