Reorder List
Problem Statement
You are given the head of a singly linked list L0 → L1 → … → Ln−1 → Ln. Rearrange it into L0 → Ln → L1 → Ln−1 → L2 → Ln−2 → … . In other words, take turns: one node from the front, then one from the back, and so on.
Relink the existing nodes. Do not change any values. The function returns nothing; the list is changed in place.
head, the first node of a singly linked list with at least one node.
Nothing. The list itself is rearranged.
Take 1 from the front, 4 from the back, 2 from the front, then 3 from the back.
With an odd count, the middle node 3 is the last one taken from the front.
- • The list has between 1 and 5 × 10^4 nodes.
- • 1 ≤ Node.val ≤ 1000
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Collect the nodes in a vector, then link the front and back nodes alternately
Slow/fast to split, reverse the second half, then weave one node from each half
An array can reach any position directly. So store every node in a vector. Then link node lo, node hi, node lo + 1, node hi − 1, and so on, moving the two indexes inward until they meet.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Linked List — Reversal translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.