Meeting Scheduler - Problem
Given the availability time slots arrays slots1 and slots2 of two people and a meeting duration, return the earliest time slot that works for both of them and is of duration duration.
If there is no common time slot that satisfies the requirements, return an empty array.
The format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end.
It is guaranteed that no two availability slots of the same person intersect with each other. That is, for any two time slots [start1, end1] and [start2, end2] of the same person, either start1 > end2 or start2 > end1.
Input & Output
Example 1 — Basic Meeting Scheduling
$
Input:
slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8
›
Output:
[60,68]
💡 Note:
The earliest common slot is [60,70] which has length 10 ≥ 8, so we schedule the meeting from 60 to 68
Example 2 — No Common Slot
$
Input:
slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12
›
Output:
[]
💡 Note:
The only overlap [60,70] has length 10 < 12, so no meeting can be scheduled
Example 3 — Multiple Overlaps
$
Input:
slots1 = [[0,20],[50,80]], slots2 = [[10,30],[70,90]], duration = 5
›
Output:
[10,15]
💡 Note:
Two overlaps exist: [10,20] and [70,80], but [10,20] is earlier, so return [10,15]
Constraints
- 1 ≤ slots1.length, slots2.length ≤ 104
- slots1[i].length = slots2[i].length = 2
- slots1[i][0] < slots1[i][1]
- slots2[i][0] < slots2[i][1]
- 1 ≤ duration ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two people's availability slots and meeting duration
2
Process
Find overlapping time periods with sufficient duration
3
Output
Earliest valid meeting slot or empty array
Key Takeaway
🎯 Key Insight: Sort time slots and use two pointers to efficiently find the earliest overlapping period with sufficient duration
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code