Meeting Scheduler
Problem Statement
Two people want to meet. slots1 lists the times person 1 is free, and slots2 lists the times person 2 is free. Each slot is [start, end]. The slots of one person never overlap each other, but they are not given in any order.
Find the earliest time slot of length exactly duration when both are free. Return it as [start, start + duration]. If there is no such slot, return an empty array.
Two lists of slots slots1 and slots2 (each slot is [start, end]), and an integer duration.
[start, start + duration] for the earliest possible meeting, or [] if none fits.
[10,50] and [0,15] share [10,15], only 5 long. [60,120] and [60,70] share [60,70], 10 long. The meeting starts at 60 and lasts 8, so [60,68].
The longest shared time is [60,70], which is only 10 long.
- • 1 ≤ slots1.length, slots2.length ≤ 10^4
- • slots1[i][0] < slots1[i][1], slots2[i][0] < slots2[i][1]
- • 0 ≤ slots1[i][j], slots2[i][j] ≤ 10^9
- • 1 ≤ duration ≤ 10^6
- • One person's slots never overlap each other
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Try every pair of slots and keep the earliest overlap that is long enough
Sort both lists, walk them together, return at the first overlap that is long enough
For every slot of person 1 and every slot of person 2, compute the shared part [lo, hi]. If hi − lo ≥ duration, a meeting can start at lo. Keep the smallest such lo. Since the input isn't sorted, we must look at all pairs before we know which is earliest.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Intervals translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.