v9.1.1
Menu

Reorder List

mediumFREELinked ListBlind 75

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

More from Blind 75

solution.py

Test results

Sign in to run your code against the test cases.