You are given a queue Q containing N integers, where N is an even number. Rearrange the elements of the queue by interleaving the first half of the queue with the second half.
Note: Return the rearranged queue as a vector or ArrayList.
Example 1
Input: N = 6, Q = {1, 2, 3, 4, 5, 6}
Output: {1, 4, 2, 5, 3, 6}
Explanation: The first half of the queue is {1, 2, 3}, and the second half is {4, 5, 6}. After interleaving the first half with the second half, the final queue becomes {1, 4, 2, 5, 3, 6}.
Example 2
Input: N = 8, Q = {10, 20, 30, 40, 50, 60, 70, 80}
Output: {10, 50, 20, 60, 30, 70, 40, 80}
Explanation: The first half of the queue is {10, 20, 30, 40}, and the second half is {50, 60, 70, 80}. After interleaving the first half with the second half, the final queue becomes {10, 50, 20, 60, 30, 70, 40, 80}.
Sign in to write, run, and submit your solution against the full test suite.