Merge Two Sorted Arrays
EasyP1Coding
a and b are two arrays, each sorted in non-decreasing order. Return a new array containing all elements of both, also sorted in non-decreasing order. Either array may be empty.
Example 1
- Input
- a = [1,3,5], b = [2,4,6]
- Output
- [1,2,3,4,5,6]
Example 2
- Input
- a = [], b = [1]
- Output
- [1]
Example 3
- Input
- a = [-5,0,3], b = [-2,2]
- Output
- [-5,-2,0,2,3]
Constraints
- 0 <= a.length, b.length <= 10^5
- -10^9 <= a[i], b[i] <= 10^9
- Both arrays are sorted in non-decreasing order.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.