← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026Remote

Summary

Meta SWE coding round, one problem the whole session: merge two sorted interval arrays into a unified sorted union. Pretty focused interview, no fluff.

Questions Asked (1)

Q1

Given two sorted interval arrays A and B (each sorted by start), merge them and return the union of all intervals with overlaps combined, sorted by start.

Algorithms & Data Structures
Author's notes

My first instinct was to just concat both arrays and sort, then do the standard merge pass.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique to traverse both sorted arrays simultaneously, merging 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. Continue until all intervals are processed, then append any remaining intervals from either array.

Pro tip: Clarify upfront whether the input intervals are closed or half-open, as this affects overlap conditions. Also, mention that you can optimize by early termination if one array is exhausted, but ensure to handle the remaining intervals efficiently.

1. Clarify assumptions and edge cases

Confirm interval inclusivity (e.g., [start, end] vs [start, end)), and discuss edge cases like empty arrays, single intervals, or non-overlapping intervals.

2. Initialize pointers and result list

Set pointers i and j to 0 for arrays A and B, and create an empty list to store merged intervals.

3. Iterate with two pointers

While both pointers are within bounds, compare the start times of A[i] and B[j]. Select the interval with the smaller start, then merge it with the last interval in the result if they overlap; otherwise, append it.

4. Process remaining intervals

After one array is exhausted, iterate through the remaining intervals in the other array, merging them with the last interval in the result as needed.

5. Return merged result

Return the result list containing the union of all intervals, sorted by start time.

Key Points to Mention

  • Two-pointer technique for merging sorted arrays
  • Overlap condition: next.start <= current.end (for closed intervals)
  • Time complexity: O(m + n) where m and n are the lengths of A and B
  • Space complexity: O(m + n) for the output (or O(1) extra if output not counted)
  • Handling of edge cases: empty arrays, single intervals, non-overlapping intervals
  • Stability: preserving order when intervals have the same start time

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