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.
Complete the function mergeThreeSortedArrays in the editor.
mergeThreeSortedArrays has the following parameters:
int a[]: the first sorted arrayint b[]: the second sorted arrayint 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
- Diagonal Traverse (for E4 ;)PHONE SCREEN · Seen Mar 2025
- Find Peak ElementPHONE SCREEN · Seen Mar 2025
- Find Pair Closest to K (for E5 :)PHONE SCREEN · Seen Feb 2025
- Get Minimum Round Trip Cost (: for E4 && E5 :)PHONE SCREEN · Seen Feb 2025
- Max Consecutive Ones III (for E5 :)PHONE SCREEN · Seen Feb 2025
- Nested List Weight Sum (for E4)PHONE SCREEN · Seen Feb 2025
- Sliding Window Average (Meta Canada, E4/E5 :)PHONE SCREEN · Seen Dec 2024
- Build Blocks and Obstacles on a Number LineSeen Oct 2024
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