Reorder List Problem

Reorder List Problem — ExecCode Medium DSA Practice

Solve the Reorder List problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

You are given the head of a singly linked list. Reorder it to: L0 → Ln → L1 → Ln-1 → L2 → ... You must reorder the nodes themselves (change next pointers), not create new nodes or change node values. For example, 1→2→3→4 becomes 1→4→2→3.

Examples

Input head = [1, 2, 3, 4]; Output [1, 4, 2, 3]. Input head = [1, 2, 3, 4, 5]; Output [1, 5, 2, 4, 3]. Input head = [1, 2]; Output [1, 2]

Constraints

1 ≤ list length ≤ 5×10⁴

Practice Reorder List free on ExecCode. Browse DSA problems, topic map, and placement guides.