Fold List on Itself

Reorder a linked list as if it were folded back on itself.

Statement

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

L0L_{0}L1L_{1}L2L_{2} → … → Ln2L_{n-2}Ln1L_{n-1}LnL_{n}

We’ll reorder it as follows:

L0L_{0}LnL_{n}L1L_{1}Ln1L_{n - 1}L2L_{2}Ln2L_{n - 2} → …

We may not modify the values in the list’s nodes. Only the links between nodes may be changed.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.