1470. Shuffle the Array


You’re given an array called nums that is composed of 2n elements in the following format:

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


The approach for this problem can be fairly straightforward. You could first instantiate an empty array that we will eventually return as the final output array (in my case, I named it res).

res = []
for i in range(n):
res.append(nums[i + n])





Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Kim

John Kim

iOS Developer | Full Stack Developer | Software Engineer | LinkedIn: john-kim-developer | GitHub: cloudiosx | Portfolio: cloudiosx.com