Tap here to switch tabs
Problem
Submissions

Problem: Shuffle the Array

med
30 min
Try to solve the Shuffle the Array problem.

Statement

You are given an integer array nums of length 2n2n, where the first nn elements are x1, x2, ..., xn and the last nn elements are y1, y2, ..., yn. Return a new array formed by interleaving these two halves in the order x1, y1, x2, y2, ..., xn, yn.

Implement List[int] shuffle(self, List[int] nums, int n) to produce the shuffled array.

Constraints:

  • 1≤1 \leq n ≤500\leq 500

  • nums.length ==== 2n2n

  • 1≤1 \leq nums[i] ≤103\leq 10^3

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shuffle the Array

med
30 min
Try to solve the Shuffle the Array problem.

Statement

You are given an integer array nums of length 2n2n, where the first nn elements are x1, x2, ..., xn and the last nn elements are y1, y2, ..., yn. Return a new array formed by interleaving these two halves in the order x1, y1, x2, y2, ..., xn, yn.

Implement List[int] shuffle(self, List[int] nums, int n) to produce the shuffled array.

Constraints:

  • 1≤1 \leq n ≤500\leq 500

  • nums.length ==== 2n2n

  • 1≤1 \leq nums[i] ≤103\leq 10^3