会议日程安排
Meeting Scheduler
题目详情
问题:会议日程安排
考察:数组、双指针
来源:Citadel
链接:https://www.jointaro.com/interviews/questions/meeting-scheduler/
You are given the availability time slots arrays slots1 and slots2 of two people and a meeting duration duration. Your task is to find the earliest time slot that both people can have a meeting of the given duration.
Each time slot is represented as an interval [start, end], representing an available time slot from start to end (inclusive).
Return the earliest time slot [start, end] such that both people have availability for a meeting of the given duration. If there is no solution, return an empty list [].
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 <= 104slots1[i].length, slots2[i].length == 20 <= slots1[i][0] < slots1[i][1] <= 1090 <= slots2[i][0] < slots2[i][1] <= 109duration >= 1
解析
思路:分别按开始时间排序两个可用时间段列表,用双指针比较当前两段的交集。若交集长度至少 duration,返回最早交集;否则推进结束时间更早的一段。
复杂度:排序 O(m log m+n log n),扫描 O(m+n),空间 O(1) 到 O(log n)。