A logging system keeps two independently sorted lists of readings that must be combined into a single sorted list. The first list's underlying storage array was allocated with extra trailing capacity -- exactly enough unused slots to also hold every reading from the second list -- while the second list is stored in its own separate array. Merge the two lists into one ascending list of the combined length.
Line 1 contains two integers m and n: the number of meaningful readings in the first list and the number of readings in the second list.
Line 2 contains m + n integers: the first m of these are the first list's readings, already sorted in ascending order; the remaining n values are unused placeholder slots and may be ignored.
Line 3 contains n integers: the second list's readings, already sorted in ascending order.
Print the m + n merged readings, in ascending order, separated by single spaces on one line. If m + n = 0, print an empty line.
0 <= m, n <= 1000-10^6 <= (each reading) <= 10^6Example 1
Input
3 3 1 2 3 0 0 0 2 5 6
Expected
1 2 2 3 5 6
Explanation
The first list's meaningful readings are [1, 2, 3] (the trailing three 0s are unused placeholder slots) and the second list is [2, 5, 6]. Merging them in ascending order gives [1, 2, 2, 3, 5, 6].
Example 2
Input
0 1 0 1
Expected
1
Explanation
The first list has no meaningful readings (m=0; its single slot is just an unused placeholder), and the second list is [1]. The merged result is simply [1].
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →