You are given two sorted arrays list1 and list2, along with
their lengths m and n.
Your task is to merge them into a single sorted array inside list1.
• list1 has enough space to hold all elements (size m + n).
• Only the first m elements of list1 are valid; the remaining positions are 0
and act as empty slots.
• list2 has n valid elements.
Input: list1 = [2,4,7,0,0,0], m = 3 list2 = [1,3,6], n = 3
Output: [1,2,3,4,6,7]
Explanation:
Merge [2,4,7] and [1,3,6] into [1,2,3,4,6,7].
Input: list1 = [5], m = 1 list2 = [], n = 0
Output: [5]
Explanation:
Nothing to merge; result is [5].
Input: list1 = [0], m = 0 list2 = [8], n = 1
Output: [8]
Accepted:
Submission: