← Questions

Merge three sorted arrays without duplicates

0
MetaCodingLast asked Apr 2026

A coding interview question asked in Meta's technical phone screen, last asked Apr 2026. It tests arrays, two pointers and merging.

Given three integer arrays, each sorted in non-decreasing order, merge them into one sorted array that contains each distinct value exactly once. Walk the three arrays together in a single pass instead of concatenating and sorting.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • merge_three(a: list[int], b: list[int], c: list[int]) -> list[int]

Example

merge_three([1, 2, 2, 5], [2, 3, 4], [1, 4, 6])  ->  [1, 2, 3, 4, 5, 6]
merge_three([], [], [])                          ->  []
merge_three([7, 7], [], [7])                     ->  [7]

Constraints

  • 0 <= len(a), len(b), len(c) <= 100,000; values in [-10^9, 10^9].
  • Target O(n) time for n total elements, plus the output.

Clarifying questions

  • Are duplicates possible within one array as well as across arrays?
  • Can any of the arrays be empty?
  • Should the result be a new array, or written into one of the inputs?

What a strong answer covers

  • Three pointers: take the smallest current value, append it if it differs from the last appended value, and advance every pointer sitting on that value (or each pointer separately and rely on the last-value check).
  • Clean handling of exhausted arrays (treat them as infinity).
  • O(n) time and O(1) extra space besides the output, compared with O(n log n) for concatenate-and-sort.
  • Generalising: k arrays with a min-heap in O(n log k).
  • Tests: empty arrays, all identical values, one array much longer than the others.

Follow-ups

  • Return only the values present in all three arrays (the intersection).
  • Merge k sorted arrays.
  • The arrays are streams too large for memory.

Where it's asked

  • Meta · Technical phone screen · Last asked Apr 202645 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted

What it tests

arrays · two pointers · merging

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding