← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Did a technical phone screen for a Software Engineer role at Meta. One coding question, classic interval merging problem. Nothing too wild but it's the kind of thing that punishes you if you skip the sorting step.

Questions Asked (1)

Q1

Given a list of closed intervals, write a function that merges all overlapping intervals and returns a list of non-overlapping intervals covering the same ranges.

Algorithms & Data Structures
Author's notes

Sort by start time first, that's the whole trick.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying assumptions (e.g., intervals are closed, input may be unsorted). Then propose sorting intervals by start time and merging in a single pass, explaining the logic and edge cases. Finally, analyze time and space complexity and discuss potential optimizations or variations.

Pro tip: Mention that sorting is the key to achieving O(n log n) time, and that the merge step is O(n) after sorting. Also, proactively discuss how to handle edge cases like empty input, single interval, and intervals that touch at endpoints (e.g., [1,2] and [2,3] should merge if closed).

1. Clarify the problem

Ask about interval inclusivity (closed vs. open), input size, whether intervals are sorted, and expected output format. Confirm that overlapping includes touching endpoints if closed.

2. Outline the approach

Propose sorting intervals by start time. Then iterate through sorted intervals, merging with the last interval in the result if they overlap; otherwise, add the current interval to the result.

3. Walk through an example

Use a small example like [[1,3],[2,6],[8,10],[15,18]] to demonstrate the merging process step by step, showing how the result is built.

4. Analyze complexity

State that sorting takes O(n log n) time and the merge pass takes O(n) time, leading to O(n log n) overall. Space complexity is O(n) for the output (or O(log n) to O(n) for sorting, depending on implementation).

5. Discuss edge cases and optimizations

Cover edge cases: empty input, single interval, all overlapping, none overlapping, and intervals with same start. Mention that if input is already sorted, we can skip sorting and achieve O(n) time.

Key Points to Mention

  • Sorting intervals by start time is crucial for efficient merging.
  • Merge condition: if current interval's start <= last merged interval's end, they overlap (for closed intervals).
  • Time complexity: O(n log n) due to sorting; space complexity: O(n) for output.
  • Edge cases: empty list, single interval, intervals that touch at endpoints, unsorted input.
  • If input is already sorted, the algorithm runs in O(n) time.
  • The output intervals are non-overlapping and sorted by start time.

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