Practice/LinkedIn/Leetcode 21. Merge Two Sorted Lists
CodingMust
You are given two sorted arrays of integers in ascending order. Your task is to merge these two arrays into a single sorted array that contains all elements from both input arrays while maintaining the ascending order.
Both input arrays are already sorted, and your solution should take advantage of this property to efficiently combine them.
Example 1:
Input: list1 = [1, 2, 4], list2 = [1, 3, 4] Output: [1, 1, 2, 3, 4, 4] Explanation: Merging the two sorted arrays results in [1, 1, 2, 3, 4, 4]
Example 2:
Input: list1 = [], list2 = [0] Output: [0] Explanation: When one array is empty, the result is the other array
Example 3:
Input: list1 = [], list2 = [] Output: [] Explanation: Two empty arrays produce an empty result
Example 4:
Input: list1 = [1, 3, 5], list2 = [2, 4, 6] Output: [1, 2, 3, 4, 5, 6] Explanation: Elements are interleaved to maintain sorted order