Free Time for Every Meeting Room
Updated
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 Phone Screen questions
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Task Processor: Dependencies and DeadlinesPHONE SCREEN · Seen Aug 2026
- Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Order Queries by Shortest Processing TimePHONE SCREEN · Seen Apr 2026
- Party Time by Town and Quiet Gaps by CityPHONE SCREEN · Seen Jan 2026
- Party Windows and Dead Zone TimePHONE SCREEN · Seen Oct 2025
- Overlap Duration of Two Time IntervalsPHONE SCREEN · Seen Jun 2025
- Multi-Head Attention BlockPHONE SCREEN · Seen Mar 2025
- Top-K SamplerPHONE SCREEN · Seen Mar 2025
Similar questions at other companies
- Merchant Capacity Interval MergeDoorDash · PHONE SCREENDoorDash interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Merge Collinear Point SegmentsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Lab and Consultation Appointment MatchingAssort Health · PHONE SCREENAssort Health interview questions
- Unique Active Pins by Time SegmentPinterest · ONSITE INTERVIEWPinterest interview questions
- Peak Process MemoryNutanix · ONSITE INTERVIEWNutanix interview questions
- Calendar Event System with Pagination and IntersectionLead Bank · ONSITE INTERVIEWLead Bank interview questions
- Top Error Types in a Time WindowNotion · ONSITE INTERVIEWNotion interview questions
- Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
- Worker Management (Promotion Track), Part 4: Full-Shift Double PayAirbnb · OAAirbnb interview questions