Mid/Senior

Meeting Scheduler

Given the availability time slots of two people, slots1 and slots2, where each slot is represented as [start, end], find the earliest time interval that works for both people and has length at least duration.

A time interval [start, start + duration] is valid if it is fully contained inside one slot from slots1 and one slot from slots2.

Return the earliest possible meeting time as [start, start + duration]. If no such meeting time exists, return an empty array [].

The time slots for each person are non-overlapping, but they may not be sorted. Your solution should efficiently compare the two sets of intervals.

Example 1
Inputslots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8
Output[60,68]
The overlap between [60, 120] and [60, 70] is [60, 70], which can fit an 8-minute meeting starting at 60.
Example 2
Inputslots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12
Output[]
The only common overlap is [60, 70], which is 10 minutes long and cannot fit a 12-minute meeting.

Constraints

  • 1 <= slots1.length, slots2.length <= 10^4
  • 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] <= 10^9
  • 1 <= duration <= 10^6
  • Time slots belonging to the same person do not overlap.

Asked at 8 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate