Problem · Array

Merge Three Sorted Arrays

EasyMetaFULLTIMEPHONE SCREEN
See Meta hiring insights

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 Description

Complete the function mergeThreeSortedArrays in the editor.

mergeThreeSortedArrays has the following parameters:

  1. int a[]: the first sorted array
  2. int b[]: the second sorted array
  3. int c[]: the third sorted array

Returns

int[]: the sorted merged array with duplicates removed

Examples
01 · 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].
02 · 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.
More Meta problems
drafts saved locally
public int[] mergeThreeSortedArrays(int[] a, int[] b, int[] c) {
  // write your code here
}
a[1, 3, 5]
b[1, 2, 5, 6]
c[2, 4, 6]
expected[1, 2, 3, 4, 5, 6]
sign in to submit