Merge Sorted Lists

Medium
arrays Microsoft Amazon

Merge two sorted lists into one sorted list. Do not simply concatenate and sort — use the fact that both lists are already sorted to achieve O(n + m) time.

Example:

Input:  list1 = [1, 3, 5], list2 = [2, 4, 6]
Output: [1, 2, 3, 4, 5, 6]

Test Cases

Python Editor

Output

Click "Run" to see results...