Meeting Scheduler

MediumIntervalstwo pointers

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Two people each have a list of free time slots, slots1 and slots2. A slot [start, end] means the person is free from start to end. Slots belonging to the same person never overlap, but a list may be in any order. Find the earliest time window of exactly duration that fits inside a free slot of both people. Return it as [start, start + duration]. A window fits a slot when slotStart <= start and start + duration <= slotEnd. If no such window exists, return an empty array.

Examples

Input: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8
Output: [60,68]
The slots `[60,120]` and `[60,70]` overlap on `[60,70]`, which is long enough for 8 minutes. Earlier overlaps (`[10,15]`) are too short.
Input: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12
Output: []
The longest shared window is 10 minutes long, which is shorter than 12.

Constraints

  • 1 <= slots1.length, slots2.length <= 10^4
  • slots[i].length == 2 and 0 <= slots[i][0] < slots[i][1] <= 10^9
  • Slots of one person do not overlap
  • 1 <= duration <= 10^6

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More two pointers problems