You are given two integer arrays a and b, each sorted in non-decreasing order.
Return a single array containing all elements of a and b, in non-decreasing order. Duplicates are kept, so the result has exactly a.length + b.length elements.
Examples
Example 1
Input: a = [1, 3, 5, 7], b = [2, 4, 6, 8]
Output: [1, 2, 3, 4, 5, 6, 7, 8]
Explanation: The elements of the two arrays interleave perfectly.
Example 2
Input: a = [2, 2, 4], b = [1, 2, 9]
Output: [1, 2, 2, 2, 4, 9]
Explanation: All three 2s appear in the result.
Constraints
1≤a.length, b.length≤104
−109≤a[i], b[i]≤109
a and b are each sorted in non-decreasing order.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up