Meeting Scheduler - Problem
Meeting Scheduler is a classic interval scheduling problem that simulates real-world calendar coordination.

You're given two people's availability schedules as arrays of time slots and need to find the earliest time slot where both can meet for a specified duration.

Input:
slots1: First person's available time slots as [start, end] pairs
slots2: Second person's available time slots as [start, end] pairs
duration: Required meeting length

Output:
• Return the [start, end] of the earliest valid meeting slot
• Return [] if no valid slot exists

Example: If person A is free [[10,50],[60,120]] and person B is free [[0,15],[60,70]] for a 8-minute meeting, the answer is [60,68] - the earliest overlapping slot that fits the duration.

Input & Output

example_1.py — Basic Overlap
$ Input: slots1 = [[10,50],[60,120],[140,210]] slots2 = [[0,15],[60,70]] duration = 8
Output: [60,68]
💡 Note: The earliest overlap is between [60,120] and [60,70], giving us [60,70]. Since we need 8 minutes and have 10 minutes available, we can schedule from 60 to 68.
example_2.py — No Valid Meeting
$ Input: slots1 = [[10,50],[60,120],[140,210]] slots2 = [[0,15],[60,70]] duration = 12
Output: []
💡 Note: The only overlap [60,70] has duration 10, which is less than required 12 minutes. No valid meeting slot exists.
example_3.py — Multiple Overlaps
$ Input: slots1 = [[10,60],[120,200]] slots2 = [[20,30],[40,50],[180,250]] duration = 8
Output: [20,28]
💡 Note: Multiple overlaps exist: [20,30] and [40,50] with first slot, [180,200] with second slot. The earliest valid meeting starts at 20.

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]
  • 0 ≤ slots1[i][j], slots2[i][j] ≤ 109
  • 1 ≤ duration ≤ 106
  • No overlapping slots within same person's schedule

Visualization

Tap to expand
Meeting Scheduler: Finding Optimal Time Slot👔 Executive A's Schedule10:00-12:3015:00-17:0019:00-21:30👩‍💼 Executive B's Schedule9:00-10:1515:00-16:1018:00-19:40Pointer APointer B📅 OVERLAP FOUND!15:00 - 16:10 (70 mins)✅ MEETING SCHEDULEDTime: 15:00 - 15:30Duration: 30 minutes
Understanding the Visualization
1
Setup Pointers
Place one pointer on each person's first available slot
2
Check Overlap
See if current slots from both people overlap sufficiently
3
Move Forward
Advance the pointer whose slot ends earlier to find next potential overlap
4
Return Result
When we find sufficient overlap, schedule the meeting at the earliest possible time
Key Takeaway
🎯 Key Insight: By using two pointers and advancing the one with the earlier end time, we efficiently find overlaps without checking all combinations, reducing time complexity from O(n*m) to O(n+m).
Asked in
Google 45 Amazon 38 Microsoft 32 Meta 28
42.0K Views
High Frequency
~18 min Avg. Time
1.3K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen