Merge Sorted Arrays
You get two arrays a and b, each sorted from smallest to largest. Return one array with all of their numbers, also sorted from smallest to largest. Numbers that appear in both arrays appear in the answer as many times as they appear in total.
Constraints
- 0 ≤ length of
a, length ofb≤ 4,000 - -1,000,000,000 ≤ each number ≤ 1,000,000,000
aandbare sorted in non-decreasing order.
Example 1
Input
a = [1,3,5]
b = [2,4,6]
Output
[1,2,3,4,5,6]
Why:
The numbers take turns coming from each array.
Example 2
Input
a = [1,2,2]
b = [2,9]
Output
[1,2,2,2,9]
Why:
All three 2s are kept.
Example 3
Input
a = []
b = [0]
Output
[0]
Why:
An empty array adds nothing.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –