Free Windows Between Busy Intervals
Updated
Problem statement
Given occupied time intervals busy, return every positive-length free interval strictly between the earliest occupied start and the latest occupied end.
For this exercise, assume intervals use integer timestamps and are half-open: [start,end). Overlapping or touching occupied intervals form one occupied block. Time before the first occupied block or after the last occupied block is excluded. With fewer than two disjoint occupied blocks, return an empty array.
Return the gaps as [start,end] rows in increasing start order. The supplied schedules have already been read from their input interface; no network calls are required.
Function
freeWindows(busy: int[][]) → int[][]Examples
Example 1
busy = [[4,7],[1,3],[9,12]]return = [[3,4],[7,9]]The occupied blocks are [1,3), [4,7), and [9,12). Their two internal gaps are returned.
Example 2
busy = [[1,5],[2,3],[5,8],[10,11]]return = [[8,10]]The nested and touching intervals combine into [1,8). The remaining gap is [8,10).
Example 3
busy = []return = []No occupied blocks means there are no bounded internal gaps.
Constraints
- For this exercise, assume
0 <= busy.length <= 100000. - Each row has two integers with
0 <= start < end <= 10^9. - The input may be unsorted and may contain duplicate or nested intervals.
More Scale AI Online Assessment questions
- Part 2: Batch Access ReviewOA · Seen Nov 2026
- Part 1: The Narrowest KeyOA · Seen Nov 2026
- Build Sessions from Unordered Events (Part 1)OA · Seen Oct 2026
- Match Billing Charges to User Sessions (Part 2)OA · Seen Oct 2026
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Compare Labeling Worker AnnotationsOA · Seen Mar 2025
- Count Stable Server SubsegmentsOA · Seen Nov 2024
- Distinct OR Values of Increasing SubsequencesOA · Seen Nov 2024
- Running Through Walls with Limited EnergyOA · Seen Sep 2024
- Relative Score Graph ComponentsOA · Seen Sep 2023
Similar questions at other companies
- Earliest Meeting Time for All EmployeesCapital One · OACapital One interview questions
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Maximum Interactive Team SizeMicrosoft · OAMicrosoft interview questions
- Largest Team Where Every Pair OverlapsWalmart · OAWalmart interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions
- Meeting Rooms IIUber · PHONE SCREENUber interview questions