Problem · Array
Merge Two Arrays Into Sorted Order
Learn this problemProblem statement
You are given two integer arrays a and b. The arrays are not necessarily sorted.
Return a new array that contains every value from a and every value from b in non-decreasing order.
Equal values may come from either array; preserve all copies.
Function
mergeTwoArraysSorted(a: int[], b: int[]) → int[]Examples
Example 1
a = [1,3]b = [2,4]return = [1,2,3,4]The combined values are 1, 3, 2, 4. Sorted non-decreasing order is 1, 2, 3, 4.
Example 2
a = [5,1]b = [4]return = [1,4,5]a is not sorted. Merging and sorting produces 1, 4, 5.
Constraints
0 <= a.length, b.length <= 10^4.-10^9 <= a[i], b[j] <= 10^9.