A music app stores a duet queue as a single concatenated array of 2n integers: the first n values are ratings for playlist X, in order x_1, x_2, ..., x_n, and the last n values are ratings for playlist Y, in order y_1, y_2, ..., y_n.
The app's "duet shuffle" feature builds one merged playback queue of length 2n by alternating one rating from X with the corresponding rating from Y, in the order x_1, y_1, x_2, y_2, ..., x_n, y_n.
Given n and the concatenated array, output the duet-shuffled queue.
Line 1: an integer n. Line 2: 2n integers, the concatenated array (first the n X-values, then the n Y-values).
A single line containing the 2n shuffled integers, space-separated, in order x_1 y_1 x_2 y_2 ... x_n y_n.
Example 1
Input
3 10 20 30 1 2 3
Expected
10 1 20 2 30 3
Explanation
n=3, so the first 3 values (10, 20, 30) are playlist X and the last 3 (1, 2, 3) are playlist Y. Interleaving gives x1,y1,x2,y2,x3,y3 = 10 1 20 2 30 3.
Example 2
Input
2 7 8 15 16
Expected
7 15 8 16
Explanation
n=2, so X = (7, 8) and Y = (15, 16). Interleaving gives 7 15 8 16.
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 →