Earliest Common Meeting Slot of a Given Length for Two Calendars
Last updated: November 29, 2026
Quick Overview
Given two people's free time slots in Google Calendar, each a list of non-overlapping [start, end] intervals, and a meeting duration, return the earliest [start, start + duration] slot that fits in both, or an empty list.
0
0
0 solved
Given two people's free time slots in Google Calendar, each a list of non-overlapping [start, end] intervals, and a meeting duration, return the earliest [start, start + duration] slot that fits in both, or an empty list.
A Google onsite question grounded in Calendar's find-a-time feature. The interviewer checks sorting each list, walking two pointers over intervals, computing overlaps correctly, and advancing the interval that ends first.
What the Interviewer Expects
- Sorts both lists by start time
- Computes overlap as max of starts and min of ends
- Advances the interval that ends first
- Returns the earliest fit and stops
- Handles touching intervals and zero-length overlaps
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Generalize to k attendees.
- What if you need every slot of the given duration, not just the earliest?
- How would you handle time zones and working-hours constraints?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
aandb, lists of[start, end]withstart < end, non-overlapping within each list but not necessarily sorted; integerduration > 0. - Output:
[s, s + duration]for the earliest `s...
High-Level Design
Sort both lists by start. Use pointer i into a and j into b. The overlap of the current two slots is [max(a_start, b_start), min(a_end, b_end)]. If its length is at least duration, return ...