Skip to content

Practice Reorder List

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#143
LeetCode Problem

Reorder List

Problem Statement

For a singly linked list L0 -> L1 -> ... -> Ln, rearrange its nodes into L0 -> Ln -> L1 -> L(n-1) -> L2 -> L(n-2) -> ... . Change next pointers only; do not replace node values. Update the original list. Practice approach: Find the midpoint with slow and fast pointers, disconnect and reverse the second half, then weave the two halves together. Terminate the final next pointer to avoid a cycle. This uses O(n) time and O(1) extra space.

Source: Reorder List on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
head = [1,2,3,4]
Output
[1,4,2,3]

# Example 2

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

Constraints

The list contains between 1 and 50000 nodes.
1 <= Node.val <= 1000

Related LeetCode Problems

Practice more problems similar to Reorder List.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.