Shuffle the Array - LeetCode

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].

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0c1d78f2-c98e-43db-befd-e5eac2fde9e8/Screen_Shot_2021-03-30_at_10.41.32_AM.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/34bd0aa5-3835-4a0e-bec8-78427fdae431/Untitled_Notebook_(1)-25.jpg

"""
1470. Shuffle the Array

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].

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

nums = [2,5,1,3,4,7]
n = 3
count = 1
print(nums)

i = 0
while i < n - 1:
    num = nums.pop(n+i)
    nums.insert(count, num)
    
    i += 1
    count += 2

print(nums)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/603295c9-76f1-4e51-b59a-6e4ac4ee01ed/Screen_Shot_2021-03-30_at_10.42.38_AM.png