Formatted question description: https://leetcode.ca/all/1229.html

# 1229. Meeting Scheduler

Medium

## Description

Given the availability time slots arrays slots1 and slots2 of two people and a meeting duration 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.

Example 1:

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

Output: [60,68]

Example 2:

Input: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12

Output: []

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

## Solution

First, sort both slots1 and slots2 according to start time in ascending order.

Next, use two indices for both slots arrays to point to slots. If the two slots from two arrays have no intersection, then find the index of the slot with a smaller end time, and increase the index by 1. If the two slots from two arrays have intersection, then check whether the intersection range is at least duration. If so, obtain the smallest possible start and set end = start + duration, add both start and end to the result list, and return the result list. Otherwise, find the index of the slot with a smaller end time, and increase the index by 1. If both slots have the same end time, then increase both indices by 1. If no common time slot with range duration is found, return an empty list.