← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Meta coding round, one problem about finding free time slots across multiple people's schedules. Pretty classic interval problem but the details trip you up if you're not careful.

Questions Asked (1)

Q1

Given a list of schedules where each person has a sorted list of non-overlapping busy intervals, find all time slots where every person is free. Only consider the range between the earliest start and latest end across all schedules.

Algorithms & Data Structures
Author's notes

My first instinct was to merge all the busy intervals into one big union and then just look at the gaps.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, determine the global time window by finding the minimum start and maximum end across all busy intervals. Then, merge all busy intervals from all people into a single list of non-overlapping intervals, and finally compute the free intervals within the global window by taking the gaps between merged busy intervals. Alternatively, use a sweep-line approach with events to track the number of busy people at any time.

Pro tip: Clarify edge cases upfront, such as empty schedules or no common free time, and discuss how to handle them. Also, mention that the solution can be optimized to O(N log N) where N is total number of intervals, and that using a heap for merging might be more efficient if schedules are large.

1. Clarify the problem and constraints

Ask questions to confirm details: Are intervals inclusive? What if someone has no busy intervals? Should the output be sorted? What is the expected input size? This ensures you understand the requirements and can tailor your solution.

2. Determine the global time window

Iterate through all schedules to find the earliest start time and the latest end time among all busy intervals. This defines the range within which we need to find free slots.

3. Merge all busy intervals

Collect all busy intervals from all people into a single list, sort them by start time, and merge overlapping intervals. This gives a consolidated view of when at least one person is busy.

4. Compute free intervals

Within the global window, identify the gaps between the merged busy intervals. These gaps represent times when everyone is free. Handle the boundaries: if the first busy interval starts after the global start, there is a free slot from global start to that start; similarly for the end.

5. Analyze complexity and discuss optimizations

State the time complexity: O(N log N) due to sorting, where N is total number of intervals. Mention that if schedules are already sorted, a k-way merge using a heap can achieve O(N log k) where k is number of people. Also, discuss space complexity.

Key Points to Mention

  • Merging intervals: sorting by start time and combining overlapping intervals.
  • Global window: min start and max end across all busy intervals.
  • Free intervals are the complement of merged busy intervals within the global window.
  • Edge cases: empty schedules, no free time, single person, intervals touching at endpoints.
  • Time complexity: O(N log N) for sorting, or O(N log k) with heap if schedules are sorted.
  • Alternative approach: sweep line with events (start/end) to track busy count.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.