Sofi OA 面试真题解析:Meeting Scheduler 会议时间安排

15次阅读
没有评论

Problem statement

Imagine that you want to schedule a meeting of a certain duration with a coworker.

You have access to your calendar and your coworker’s calendar (both of which contain your respective meetings for the day, in the form of [startTime, endTime]).

Write a function that takes in your calendar, your coworker’s calendar, and the duration of the meeting that you want to schedule, and returns a list of all the time blocks (in the form of [startTime, endTime]) during which you could schedule the meeting.

Sample input:

Calendar1: [['9:00', '10:30'], ['12:00', '13:00'], ['16:00', '18:00']]
Calendar2: [['10:00', '11:30'], ['12:30', '14:30'], ['14:30', '15:00'], ['16:00', '17:00']]
Meeting duration: 30

Sample output:

[['11:30', '12:00'], ['15:00', '16:00']]

这道题的核心是把两个人当天的忙碌时间合并起来,再从合并后的时间线中找出满足会议时长的空闲区间。通常做法是先将两个日历中的时间段按开始时间排序并合并重叠区间,然后计算相邻忙碌区间之间的空档,筛选出长度不少于给定 meeting duration 的时间块。样例中,两份日历合并后可以得到两个可安排的空闲窗口:11:30–12:00 和 15:00–16:00。

正文完
 0