Two scoreboards each store scores as a singly linked chain sorted in non-decreasing order. Fuse them into a single chain that is also sorted in non-decreasing order (keeping every value, including duplicates across the two chains).
Line 1: an integer p, the length of chain A.
Line 2: p space-separated integers of chain A, non-decreasing (empty line when p is 0).
Line 3: an integer q, the length of chain B.
Line 4: q space-separated integers of chain B, non-decreasing (empty line when q is 0).
Line 1: the total number of values, p + q.
Line 2: all values merged into non-decreasing order, space-separated (empty line if both are empty).
Example 1
Input
3 1 4 7 3 2 4 8
Expected
6 1 2 4 4 7 8
Explanation
Interleaving the two sorted chains gives 1 2 4 4 7 8.
Example 2
Input
0 2 5 9
Expected
2 5 9
Explanation
Chain A is empty, so the merged chain is just chain B: 5 9.
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 →