← Questions
Merge three sorted arrays without duplicates
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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 forntotal 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 andO(1)extra space besides the output, compared withO(n log n)for concatenate-and-sort. - Generalising:
karrays with a min-heap inO(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
ksorted 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
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
