Reorder List

Try to solve the Reorder List problem.

Statement

Given the head of a singly linked list, reorder the list as if it were folded on itself. For example, if the list is represented as follows:

L0L_{0} → L1L_{1} → L2L_{2} → … → Ln−2L_{n-2} → Ln−1L_{n-1} → LnL_{n} ​

This is how you’ll reorder it:

L0L_{0} → LnL_{n} → L1L_{1} → Ln−1L_{n - 1} → L2L_{2} → Ln−2L_{n - 2} → …

You don’t need to modify the values in the list’s nodes; only the links between nodes need to be changed.

Constraints:

  • The range of number of nodes in the list is [1,500][1, 500].
  • −5000≤-5000 \leq Node.value ≤5000\leq 5000

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy