Merge Sorted Arrays with Duplicates
Problem statement
Given two integer arrays a and b, each sorted in nondecreasing order, return a new array containing all their elements in nondecreasing order.
Retain every occurrence of every value, including duplicates within an input or across both inputs. Do not change either input. Either array, or both, may be empty.
Function
mergeSortedArrays(a: int[], b: int[]) → int[]Examples
Example 1
a = [1,2,2]b = [2,3]return = [1,2,2,2,3]The value 2 occurs twice in a and once in b, so it occurs three times in the result.
Example 2
a = []b = [-2,0,0]return = [-2,0,0]An empty first array contributes no elements.
Constraints
- 0 ≤ a.length, b.length ≤ 10,000.
- −100,000,000 ≤ every array value ≤ 100,000,000.
- Both input arrays are sorted in nondecreasing order.