← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Meta SWE coding round, pretty standard interval problem. Nothing too crazy but the edge cases around touching endpoints tripped me up more than I'd like to admit.

Questions Asked (1)

Q1

Given a list of closed intervals, merge all overlapping ones (including those that touch at endpoints) and return the resulting sorted list.

Algorithms & Data Structures
Author's notes

Sort first, then sweep.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by sorting the intervals by their start times, then iterate through them while maintaining a result list. For each interval, if it overlaps or touches the last interval in the result (i.e., its start <= last end), merge them by updating the end to the maximum of both ends; otherwise, append it. This yields O(n log n) time due to sorting and O(n) space for the output.

Pro tip: Clarify the definition of 'touching' (e.g., [1,2] and [2,3] should merge) and confirm whether the input can be empty or contain invalid intervals; handling these edge cases upfront shows attention to detail and prevents bugs.

1. Clarify and validate

Ask about edge cases: empty list, single interval, intervals with start > end, and whether touching intervals should merge. Confirm the expected output format.

2. Sort intervals

Sort the intervals by their start times. If starts are equal, sorting by end is optional but can simplify merging.

3. Iterate and merge

Initialize an empty result list. For each interval, if the result is empty or the current interval's start is greater than the last merged interval's end, append it; otherwise, merge by updating the last interval's end to the maximum of both ends.

4. Return result

After processing all intervals, return the merged list, which is already sorted due to the initial sort.

5. Analyze complexity

State that time complexity is O(n log n) due to sorting, and space complexity is O(n) for the output (or O(1) extra if merging in-place is allowed).

Key Points to Mention

  • Sorting by start time is crucial for the linear scan to work correctly.
  • Overlap condition: current.start <= last.end (including equality for touching intervals).
  • Merging updates the end to max(last.end, current.end) to handle nested intervals.
  • Edge cases: empty input, single interval, intervals that are already merged, and intervals with zero length.
  • Time complexity O(n log n) and space complexity O(n) (or O(1) extra if modifying input).
  • The output is sorted because the input was sorted and merging preserves order.

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