DSA AnimatorDSA animations
Middle of the Linked List LC #876 Easy Fast / Slow Pointer
Problem

Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.

Example 1
Input: head = [1,2,3,4,5]
Output: [3,4,5]
Explanation: The middle node has value 3.
Example 2
Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
Explanation: Two middles exist (3 and 4) — return the second middle node (value 4).
Constraints: 1 ≤ list length ≤ 100  |  1 ≤ Node.val ≤ 100
Try Examples
Custom:
Linked List
slow steps: 0
fast steps: 0
fast / slow ratio: —
fast pointer progress: 0 / 0
State Variables
slow index
0
fast index
0
slow.val
—
Step Logic
Press ▶ Play or Next Step to begin the animation.
🎯
Ready
0 / 0
Select an example above and press Play.
Algorithm
1
Init both slow = head and fast = head at index 0
2
While fast != null && fast.next != null: loop continues
3
Advance slow = slow.next (1 step) and fast = fast.next.next (2 steps)
4
Loop ends — fast at null or last node. slow is now at the middle. Return slow.
Time
O(n)
Space
O(1)
Why It Works

Since fast moves exactly twice as fast as slow, when fast has covered the entire list (reaches null or the last node), slow has covered exactly half the distance — landing on the middle. For even-length lists, fast lands on the last node after covering n−1 steps, so slow ends at index ⌊n/2⌋ (the second middle), matching LeetCode's requirement.

How to solve Middle of Linked List

LeetCode 876 · Easy · Linked List · Pattern: Fast & Slow Pointers

Why the obvious approach is slow

Counting the length first and then walking half of it takes two passes. One pass is enough with two speeds.

The key idea

Move slow by one and fast by two. When fast reaches the end, slow has covered half the distance. So slow is at the middle.

Remember

When fast finishes, slow is halfway. This also finds the split point for palindrome and reorder problems.

Run the animation above on your own input, or watch the 0:59 video explanation of Middle of Linked List with a dry run and Java code.

More Linked List problems