Description

Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn], return the array in the form [x1,y1,x2,y2,...,xn,yn].

Examples

Input:nums = [2,5,1,3,4,7], n = 3
Output:[2,3,5,4,1,7]
Explanation:

Interleave two halves.

Input:nums = [1,3,2,4], n = 2
Output:[1,2,3,4]
Explanation:

With n=2, [1,3,2,4] is split into first half [1,3] and second half [2,4]. Interleaving gives [1,2,3,4] by taking x1=1, y1=2, x2=3, y2=4.

Input:nums = [10,20,30,40,50,60,70,80,90,100], n = 5
Output:[10,60,20,70,30,80,40,90,50,100]
Explanation:

With n=5, the array is split into first half [10,20,30,40,50] and second half [60,70,80,90,100]. Interleaving pairs each element from the first half with the corresponding element from the second half.

Constraints

  • 1 ≤ n ≤ 500

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!