Problem · Array
Find First Common Availability
Learn this problemProblem statement
Two people have availability intervals slotsA and slotsB. Each interval is a pair [start, end] and can host a meeting from any time at or after start through time end.
Given a positive meeting duration dur, return the earliest common interval [start, start + dur] that fits inside one interval from each person's schedule. If no common interval is long enough, return an empty array.
Each person's intervals are sorted by start time and do not overlap within that person's schedule.
Function
findFirstAvailability(slotsA: int[][], slotsB: int[][], dur: int) → int[]Examples
Example 1
slotsA = [[10,50],[60,120],[140,210]]slotsB = [[0,15],[60,70]]dur = 8return = [60,68]The overlap [10, 15] is too short. The next overlap begins at 60 and lasts ten units, so the earliest eight-unit meeting is [60, 68].
Example 2
slotsA = [[10,20]]slotsB = [[15,25]]dur = 5return = [15,20]The common interval has exactly the required duration.
Example 3
slotsA = [[1,2],[5,7]]slotsB = [[2,4],[7,9]]dur = 1return = []The schedules only touch at endpoints and have no positive-length overlap.
Constraints
0 <= slotsA.length, slotsB.length <= 100000- Every interval has exactly two integers
[start, end]with0 <= start < end <= 10^9. - Intervals in each input are sorted by start time and are pairwise non-overlapping.
1 <= dur <= 10^9