Merge Two Sorted Arrays
Problem statement
Given two integer arrays first and second, each sorted in nondecreasing order, return a new array containing all their values in nondecreasing order.
Keep every occurrence, including repeated values within either input and values present in both arrays. Either input may be empty.
Function
mergeSortedArrays(first: int[], second: int[]) → int[]Examples
Example 1
first = [1,4,4]second = [2,4,7]return = [1,2,4,4,4,7]Every occurrence of 4 remains.
Example 2
first = []second = [0,3]return = [0,3]An empty input contributes no values.
Example 3
first = [-5,-1,6]second = [-3,6]return = [-5,-3,-1,6,6]Negative values and both copies of 6 are retained.
Constraints
0 <= first.length, second.length <= 10^5.- The combined length is at most
2 * 10^5. - Values are signed 32-bit integers.
- Both inputs are sorted in nondecreasing order.