Merge Three Sorted Arrays
Reported by candidates from Meta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip away the wrapper and the Meta OA from May 2026 is just a three-way merge with dedupe. Three sorted arrays, some empty, plenty of repeats, one sorted unique array out. It's an array problem that rewards the two-pointer idea, and it punishes people who overthink it. If you have the invite sitting there, this one is a warm-up if you stay calm. StealthCoder is the safety net running invisibly during the live assessment if your mind goes blank on the pointer logic. Otherwise, you only need one clean pass and a way to skip duplicates.
The problem
You are given three integer arrays that are each sorted in non-decreasing order. Merge the arrays into one sorted array and remove duplicate values. Return the merged array in non-decreasing order. Function mergeThreeSortedArrays(a: int[], b: int[], c: int[]) → int[] Complete the function mergeThreeSortedArrays in the editor. mergeThreeSortedArrays has the following parameters: int a[]: the first sorted array int b[]: the second sorted array int c[]: the third sorted array Returns int[]: the sorted merged array with duplicates removed Examples Example 1 a = [1, 3, 5] b = [1, 2, 5, 6] c = [2, 4, 6] return = [1, 2, 3, 4, 5, 6] After merging all values and removing duplicates, the sorted result is [1, 2, 3, 4, 5, 6]. Example 2 a = [] b = [0, 0, 1] c = [1, 2] return = [0, 1, 2] Empty arrays are allowed. Duplicate 0 and 1 values are returned once. Constraints Each input array is sorted in non-decreasing order. The arrays may contain duplicate values. The arrays may be empty.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that sortedness does the work for you. Keep three pointers, one per array. Each step, take the smallest value among the pointers that are still in range. Append it only if it differs from the last value in the result, then advance every pointer sitting on that value. That gives O(n) time with no sorting and no hash set. The common pitfall is empty arrays, so guard every index check before you read. Another is dedupe against the wrong thing. Compare to the last appended element, not the previous input element. A lazy fallback is concatenating, sorting and deduping, which works but ignores the sorted input and may read as weak. If the pointer bookkeeping slips under pressure, StealthCoder is the hedge during the live OA, reading the problem and handing you a clean solution.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Merge Three Sorted Arrays cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Meta's OA.
Meta reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Merge Three Sorted Arrays FAQ
How hard is the Meta Merge Three Sorted Arrays question really?+
Easy to low-medium. The idea is simple, but the edge cases trip people: empty arrays, duplicates within one array, and duplicates across arrays. If you write the pointer loop carefully and test example 2, you're fine.
What's the trick to solving it fast?+
Use three pointers and always take the minimum of the current values. Append only if it differs from the last value in your output. Since every input is sorted, duplicates are always adjacent in the result, so one comparison is enough.
Can I just concatenate and sort?+
Yes, it's correct. Combine everything, sort, then dedupe in one pass. That's O(n log n) instead of O(n). It passes the examples, but the three-pointer merge uses the sorted guarantee and shows stronger judgment, so prefer it.
What edge cases should I test before submitting?+
Test all three arrays empty, one array empty like example 2, every element identical, and arrays of very different lengths. Also check duplicates inside a single array, such as the repeated 0 values, and negative numbers if they appear.
How do I prepare for this in 48 hours?+
Write the two-array merge from scratch, then extend it to three. Practice the dedupe check against the last output element. Do a couple of related merge problems, and time yourself so you can finish this one in about ten minutes.