Meeting Scheduler
Real-world version: Earliest Window Both Are FreeThe statement here is our own: the same inputs, outputs and technique.
Two people's free periods are given as slots1 and slots2, each entry a pair [start, end] meaning free from start up to end. A person's own periods never overlap each other.
Find the earliest moment t at which both are free for a stretch of duration, that is where the whole of t to t + duration lies inside one period of each.
Return [t, t + duration], or an empty list when no such moment exists.
Examples
Example 1
- Input
- slots1 = [[14, 27], [40, 55], [70, 90]], slots2 = [[20, 33], [50, 60], [80, 95]], duration = 8
- Output
- [80, 88]
The first overlap runs from 20 to 27, only seven long. The next runs from 50 to 55, five long. The one from 80 to 90 is ten long, so the stretch starts at 80.
Example 2
- Input
- slots1 = [[0, 5]], slots2 = [[5, 10]], duration = 1
- Output
- []
The two periods meet at a single moment and overlap over nothing, so there is no room even for a stretch of one.
Example 3
- Input
- slots1 = [[10, 20], [0, 5]], slots2 = [[0, 30]], duration = 5
- Output
- [0, 5]
The periods are not given in order, and sorting them first shows the earliest workable overlap starts at 0.
Constraints
- 1 <= slots1.length <= 10^4
- 1 <= slots2.length <= 10^4
- slots1[i].length == 2
- slots2[i].length == 2
- slots1[i][0] < slots1[i][1]
- slots2[i][0] < slots2[i][1]
- 0 <= slots1[i][j] <= 10^9
- 0 <= slots2[i][j] <= 10^9
- 1 <= duration <= 10^6
- Neither person's own periods overlap each other
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def min_available_duration(slots1: list[list[int]], slots2: list[list[int]], duration: int) -> list[int]:public List<Integer> minAvailableDuration(int[][] slots1, int[][] slots2, int duration)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's