Introduction
The Find the Middle of a Linked List problem is a very common DSA interview question related to linked lists. Interviewers like this problem because it checks your understanding of pointer movement, traversal logic, and optimization.
In simple words, this problem asks you to find the middle node of a linked list in one traversal.
What Does “Middle of a Linked List” Mean?
Given a linked list:
If the list has odd number of nodes, there is exactly one middle node
If the list has even number of nodes, most interviewers ask you to return the second middle node
Example
Odd length list:
1 → 2 → 3 → 4 → 5
Middle node = 3
Even length list:
1 → 2 → 3 → 4 → 5 → 6
Middle node = 4 (second middle)
Why Brute Force Approach is Not Ideal
A simple approach is:
Count the total number of nodes
Traverse again to reach the middle
Problems with This Approach
Requires two traversals
Less efficient
Interviewers usually expect a single-pass solution.
Optimized Approach: Slow and Fast Pointer Technique
The most efficient way to solve this problem is by using two pointers.
Key Idea (Very Simple)
Slow pointer moves one step at a time
Fast pointer moves two steps at a time
When the fast pointer reaches the end, the slow pointer will be at the middle.
Why This Technique Works
Because the fast pointer moves twice as fast:
When fast reaches the end of the list
Slow has covered half the distance
So slow naturally lands on the middle node.
Step-by-Step Explanation
Steps:
Initialize both
slowandfastpointers at the headMove
slowby one stepMove
fastby two stepsRepeat until
fastreaches the end or becomes nullslownow points to the middle node
Dry Run Example (Odd Length)
Linked List:
1 → 2 → 3 → 4 → 5
| Step | Slow | Fast |
|---|---|---|
| Start | 1 | 1 |
| 1 | 2 | 3 |
| 2 | 3 | 5 |
Join the conversation! Your thoughts help the community grow.