The problem
Return the middle node of a linked list. If there are two middles, return the second one.
Stuck? Reveal hints one at a time
How to approach it
- 1slow = fast = head.
- 2While fast && fast.next: slow steps once, fast steps twice.
- 3When fast runs out, slow is at the middle (second middle for even lengths).
Key insight
Fast/slow is the building block for list midpoints, cycle checks, and list merge sort — this is the drill version.
The solution
Watch out for
- For the FIRST middle (merge sort splitting), start fast at head.next instead.
- The while-condition order (fast before fast.next) prevents null dereference.