12. Merge Two Sorted Arrays
EasySorting~10 min
You are given two arrays that are already sorted in ascending order. Return a single array containing every element from both, still sorted ascending.
Duplicates are kept — if a value appears in both arrays, it appears twice in the result.
Examples
Example 1
- Input:
- a = [1, 3, 5], b = [2, 4, 6]
- Output:
- [1, 2, 3, 4, 5, 6]
Example 2
- Input:
- a = [1, 2], b = []
- Output:
- [1, 2]
Constraints
0 <= a.length, b.length <= 1000Both inputs are already sorted ascending.