Skip to main content

Meeting Scheduler

MediumTwo Pointers

Description

Given two people's availabilities and required duration, return the earliest time slot that works for both, or empty if none.

Examples

Input:slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8
Output:[60,68]
Explanation:

The algorithm sorts both slot lists by start time and uses two pointers to find overlapping intervals. For each pair, the overlap is [max(start1, start2), min(end1, end2)]; if this overlap's length is at least the required duration, return [overlapStart, overlapStart + duration].

Input:slots1 = [[1]], slots2 = [[1]], duration = 8
Output:[1]
Explanation:

Minimal case with a single time slot per person.

Input:slots1 = [[20,30],[50,80],[90,150]], slots2 = [[25,35],[70,100],[130,160]], duration = 15
Output:[130,145]
Explanation:

The overlaps are [25,30], [70,80], [90,100], and [130,150]. Only [130,150] is long enough for a 15-minute meeting, so the earliest valid slot is [130,145].

Constraints

  • 1 ≤ slots1.length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.