Sofi Online Assessment: Meeting Scheduler

16 Views
No Comments

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']]

The key idea is to merge both calendars into a single list of busy intervals, then scan the gaps between consecutive intervals to find all available meeting windows whose length is at least the required duration. A sorting-and-merging approach works well here, followed by a linear pass to compute free time blocks. In the sample, the valid slots are 11:30-12:00 and 15:00-16:00.

END
 0