Shuffle the Array
nums has 2 * n items, written as [x1, ..., xn, y1, ..., yn]. Return the list interleaved as [x1, y1, x2, y2, ..., xn, yn], where n is the second argument.
Example 1
nums [2,5,1,3,4,7]
n 3
returns [2,3,5,4,1,7]
x = [2, 5, 1], y = [3, 4, 7], so 2, 3, 5, 4, 1, 7.
Constraints
len(nums) == 2 * n1 <= n <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Sort by ParityBeginner
- Trend SignsBeginner
- Alternate the SignsEasy
- Drop the Lowest ScoresEasy
- Fair CutsEasy
- Final Tank LevelEasy
- Find Closest Number to ZeroEasy
- Find Disappeared NumbersEasy