Middle of Linked List

Med
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Middle of Linked List

Approach

Use two pointers starting at the head. Move slow one step and fast two steps on each iteration. When fast reaches the end, slow is at the middle. For even-length lists, this returns the second of the two middle nodes.

Complexity Analysis

Time
O(n)
Space
O(1)

Pattern

Linked List (Fast/Slow Runner)

Why It Works

The fast pointer traverses the list at double speed, so when it finishes the slow pointer has covered exactly half the distance, landing on the middle node.

Updated Feb 2026