← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta coding round, one question on interval merging. Pretty clean problem but there are enough edge cases to trip you up if you're not careful about the touching-interval condition.

Questions Asked (1)

Q1

Given two sorted arrays of intervals, return the merged union of all intervals, coalescing any that overlap or share an endpoint.

Algorithms & Data Structures
Author's notes

Two-pointer approach felt natural here since both arrays are already sorted by start time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique to traverse both sorted interval lists simultaneously, merging overlapping intervals on the fly. At each step, pick the interval with the smaller start, then merge it with the last interval in the result if they overlap or touch. Continue until all intervals from both lists are processed.

Pro tip: Clarify upfront whether intervals are closed (inclusive endpoints) and whether the input arrays can be modified. Handling edge cases like empty arrays and single intervals early shows attention to detail and prevents bugs.

1. Clarify assumptions and edge cases

Confirm that intervals are sorted by start time, closed, and that the output should be a new list. Discuss handling of empty inputs, single intervals, and intervals that only touch at endpoints.

2. Initialize pointers and result list

Set two pointers i and j to 0 for the two arrays, and create an empty result list to store merged intervals.

3. Iterate and merge

While both pointers are within bounds, compare the start times of the current intervals. Select the one with the smaller start, then merge it with the last interval in the result if they overlap or touch (i.e., if the last interval's end >= selected interval's start). Otherwise, append the selected interval to the result.

4. Process remaining intervals

After one array is exhausted, continue the same merging process with the remaining intervals from the other array.

5. Return the merged result

Once all intervals are processed, return the result list containing the merged union of intervals.

Key Points to Mention

  • Two-pointer technique to traverse both sorted arrays in linear time.
  • Merging condition: intervals overlap or touch if the last merged interval's end >= current interval's start.
  • Time complexity: O(n + m) where n and m are the lengths of the two arrays.
  • Space complexity: O(n + m) for the output list (or O(1) extra space if merging in-place is allowed).
  • Handling edge cases: empty arrays, intervals that are completely contained within others, and intervals that only share an endpoint.
  • Maintaining sorted order in the result without needing to sort again.

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