Given a singly linked list L0 → L1 → … → Ln−1 → Ln, reorder it to L0 → Ln → L1 → Ln−1 → L2 → Ln−2 → … by changing pointers, not values.
Before you code
The pattern alternates between the front and the back, but a singly linked list can only walk forward. If the back half were reversed, it would also be walkable from its end. That splits the problem into three steps you already know.
Hints
- Find the middle with fast and slow pointers, and cut the list there.
- Reverse the second half.
- Interleave the two halves: one node from the first, one from the second, until the second runs out.
- Check both odd and even lengths; for odd lengths the middle node ends up last.
Production & complexity notes
When solving Reorder list on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Fast and slow pointers to reinforce the underlying pattern.
What it practices
Combining the middle-finding pointers with reversal, from Fast and slow pointers.