Rearrange an array of length so that the values alternate between the first half and the second half.
You are given an integer array nums containing 2n elements in the form:
n elements: x1, x2, ..., xnn elements: y1, y2, ..., ynReturn the array arranged as:
[x1, y1, x2, y2, ..., xn, yn]
The goal is to interleave the two halves of the array in order.
nums of even length 2n.x1..xn.y1..yn.2n arranged as [x1, y1, x2, y2, ..., xn, yn].nums.length = 2n1 <= nExample 1
Input
nums = [2,5,1,3,4,7], n = 3
Output
[2,3,5,4,1,7]
Explanation
The first half is [2,5,1] and the second half is [3,4,7]. Interleaving them gives [2,3,5,4,1,7].
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.