Find Overlapping Free Time Between Two Sorted Calendars
Last updated: November 29, 2026
Quick Overview
Two people's free time is given as sorted lists of disjoint closed intervals. Return every interval of time when both are free, in sorted order.
Meta
November 29, 20260
0
0 solved
Two people's free time is given as sorted lists of disjoint closed intervals. Return every interval of time when both are free, in sorted order.
Scheduling across calendars shows up in Workplace and Messenger features, and interval intersection is a common Meta screen problem. Interviewers want a linear two-pointer sweep and a clear rule for which pointer advances.
What the Interviewer Expects
- Computes each overlap as max of starts and min of ends
- Advances the pointer whose interval ends first
- Treats closed intervals correctly, including single-point overlaps
- Runs in O(m + n)
- Explains why advancing the earlier end never loses an overlap
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 people's calendars.
- Return only overlaps of at least d minutes.
- What if the intervals within a list may overlap each other?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Each list is sorted by start and pairwise disjoint. Intervals are closed, so [5, 10] and [1, 5] share the point 5. Output sorted list of intersections. O(m + n) time....
High-Level Design
Use pointers i and j. The overlap of A[i] and B[j] is [max(starts), min(ends)], valid when start <= end. Then advance whichever interval ends first: it cannot overlap anything later in the other...