← Back to DSA Animator
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
fast
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.