VOOZH about

URL: https://www.geeksforgeeks.org/dsa/meeting-scheduler-for-two-persons/

⇱ Common Slot for Meeting of Two Persons - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Common Slot for Meeting of Two Persons

Last Updated : 23 Jul, 2025

You are given two lists of availability time slots, slt1[][] and slt2[][], for two people. Each slot is represented as [start, end], and it is guaranteed that within each list, no two slots overlap (i.e., for any two intervals, either start1>end2 or start2>end1).
Given a meeting duration d, return the earliest common time slot of length at least d. If no such slot exists, return an empty array.

Examples:

Input: slt1[][] = [[10,50], [60,120], [140,210]], slt2[][] = [[0,15], [60,70]], d = 8
Output: [60,68]
Explanation: The only overlap is [60,70] (10 minutes), which is enough for an 8-minute meeting, so answer is [60,68]

Input: slt1[][] = [[10,50], [60,120], [140,210]], slt2[][] = [[0,15], [60,70]], d = 12
Output: []
Explanation: The only overlap is [60, 70] (10 minutes), but 12 minutes are needed, so no valid slot exists.

We start by sorting both slots by start time. Then, use two pointer to step through both slots. For each pair, calculate the overlap as [max(start₁, start₂), min(end₁, end₂)]. If the overlap is at least d long, return that slot; otherwise, advance the pointer for the interval that finishes first.


Output
[60, 68]

Time Complexity: O(n log n), n is length of larger slot
Auxiliary Space: O(1)

Comment
Article Tags: