PIXELBANKv8.2.1
Menu

Reorder List

Given a list L: L0 → L1 → … → Ln-1 → Ln, reorder it to: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → …

Output the reordered list as space-separated values.

Example:

Input:
1,2,3,4
Output:
1 4 2 3
Reasoning:
  • The input list is split into two parts: the first half and the second half in reverse order.
  • The first half of the list is 1, 2 and the second half in reverse order is 4, 3.
  • The two halves are then merged in an alternating manner: 1 from the first half, 4 from the second half, 2 from the first half, and 3 from the second half.
  • The final output is the merged list as space-separated values: 1 4 2 3.

Constraints:

  • 1 <= number of nodes <= 5 * 10^4
  • 1 <= Node.val <= 1000
Editor

Test Results

0/0
Run code to see test results.