Skip to content

visual walkthrough

Middle of the Linked List

EasyFast & Slow PointersReported at: AmazonGoogleMeta+3

Fast/slow to find the midpoint, a sub-step of many problems.

Solve on LeetCode

The idea

A list can't jump to its middle: you only know where the middle is once you know the length.

Or let a second pointer measure it for you: move fast two steps for every one step of slow. When fast runs out of list, slow is exactly halfway.

Complexity

approachtimespace
Count, then walkO(n)O(1)
Slow and fast pointersO(n)O(1)

More walkthroughs