Meeting finder
MediumOnline Assessment
Find every time slot in a working window where a meeting of a given length fits, given everyone's calendars.
Each calendar is a list of busy intervals written "HH:MM-HH:MM" (24-hour clock, same day, start not later than end). Intervals from different calendars or the same calendar may overlap, nest or touch. All calendars are combined: a minute is busy if it lies in any interval.
Rules:
- An interval whose start equals its end is empty and is ignored completely (it gets no buffer either).
- Every other interval is extended by
bufferminutes after its end (travel time before the next meeting). Nothing is added before its start. - Busy time outside
windowis irrelevant; busy time that straddles a window edge blocks only the part inside the window. - Busy intervals that overlap or touch (one ends exactly when the next begins) leave no gap between them.
- A free gap is a maximal stretch of the window with no busy minute. It qualifies if its length is at least
lengthminutes (exactlylengthqualifies).
Input: calendars, a list of lists of interval strings; window, a string "HH:MM-HH:MM"; length, the meeting length in minutes; and buffer, the number of minutes added after every non-empty interval.
Output: a list of strings "HH:MM-HH:MM" (zero-padded), one per qualifying gap, in chronological order. Return the whole gap, not just the first length minutes of it. If no gap qualifies, return [].
Example 1
- Input:
- [[["09:00-10:00","13:00-14:00"],["09:30-11:00"]],"09:00-17:00",60,0]
- Output:
- ["11:00-13:00","14:00-17:00"]
- Explanation
- The busy times 09:00-10:00 and 09:30-11:00 overlap and merge into 09:00-11:00; the other busy time is 13:00-14:00. With no buffer, the free gaps in the 09:00-17:00 window are 11:00-13:00 (120 minutes) and 14:00-17:00 (180 minutes); both are at least 60 minutes.
Example 2
- Input:
- [[["09:00-10:00","10:15-11:00"],["12:00-12:30"]],"09:00-13:00",30,15]
- Output:
- ["11:15-12:00"]
- Explanation
- With a 15-minute buffer the busy times become 09:00-10:15, 10:15-11:15 and 12:00-12:45. The first two touch, so they merge into 09:00-11:15. The gap 11:15-12:00 is 45 minutes, long enough. The gap 12:45-13:00 is only 15 minutes and is dropped.
Example 3
- Input:
- [[["08:00-09:30","16:00-18:00","12:00-12:00"],[]],"09:00-17:00",390,0]
- Output:
- ["09:30-16:00"]
- Explanation
- 08:00-09:30 is clipped to the window as 09:00-09:30, and 16:00-18:00 becomes 16:00-17:00. The empty meeting 12:00-12:00 is ignored. The single gap 09:30-16:00 is exactly 390 minutes, which is long enough because a gap of exactly
lengthqualifies.
Constraints
0 <= calendars.length <= 10, and each calendar has at most 40 intervals- Every time is
HH:MMon a 24-hour clock from00:00to23:59; in every interval and inwindow, the start is not later than the end windowstarts strictly before it ends1 <= length <= 1,440and0 <= buffer <= 120