Skip to main content
All Questions

Reorder linked list.

Medium
Unlock detailed company stats for this questionUpgrade

You're given the head of a singly linked list L0 → L1 → ... → Ln-1 → Ln. Reorder it in place to L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → ....

Change the links between nodes rather than the values stored in them. The function doesn't return anything.

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 has between 1 and 5 * 10^4 nodes.
  • 1 <= Node.val <= 1000

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.