Middle of Linked List
An easy Linked List interview guide. Task statement, worked examples, intuition, and step-by-step solutions.
- Topic
- Linked List
- Sheets
- 3
- Core for
- 3 roles
The problem
Find the middle node of a linked list. If there are two middle nodes, return the second one.
Example 1
- Input
- [1,2,3,4,5]
- Output
- node with value 3
Example 2
- Input
- [1,2,3,4,5,6]
- Output
- node with value 4
Example 3
- Input
- [1]
- Output
- node with value 1
Constraints
- 1 <= n <= 100
How to think about it
Updated 2026-09-09When one traveler moves at twice the speed of another, the moment the faster traveler reaches the finish line, the slower traveler is at the exact halfway point. That lets you locate the midpoint in a single pass without knowing the total length beforehand.
Approaches, worst first
Count and traverse
time O(n) · space O(1)
Traverse the list once to tally the total length n. Compute n / 2 and run a second traversal from the head to step forward that many nodes. Correct and simple, but visits the first half of the list twice.
Fast and slow two-pointer strideWrite this one
time O(n) · space O(1)
Start both slow and fast at head. In each iteration, advance slow by one node and fast by two nodes while fast and fast.next are non-null. When fast halts, slow rests precisely on the second middle node for even lengths and the exact center for odd lengths.
Where people lose marks · 3
- Writing `fast.next != null && fast != null` in that order causes a null pointer exception on even-length lists because fast is evaluated after dereferencing fast.next.
- Using `fast.next.next != null` as the loop condition stops one step too early on even-length lists, mistakenly returning the first middle node instead of the requested second middle.
- Single-node lists where `head.next == null` must exit immediately returning head without attempting any pointer jumps.
The theory behind it
Linked List — the ground this problem stands on. All Linked List problems
What Linked List is
A linked list is a chain of separate cargo cars connected by coupling hooks, scattered anywhere across memory rather than sitting in a tidy contiguous row. Each car, called a node, holds a single piece of data and a pointer directing traffic to the address of the next car in line. Because nodes connect only by directional links, jumping straight to the tenth car is impossible without walking past the first nine.
When to reach for it
Choose a linked list when a problem requires frequent insertions and deletions at known positions without shifting whole blocks of surrounding memory. Problems mentioning pointer splicing, reversing subsequences in place, merging sorted streams, or detecting cycles in linear chains strongly point here. It is ideal when total capacity is unpredictable and memory allocation must happen one individual node at a time.
How the pattern works
Think in terms of pointer rewiring before dereferencing. Keep a dummy head node pointing to the start of the list so modifications to the initial item do not require separate edge logic. Always save references to neighboring nodes into temporary variables before cutting or redirecting forward links. When diagnosing loops or locating middle nodes, advance two references simultaneously at differing velocities so traversal completes without supplementary storage.
More Linked List problems
Target Roles
Core requirement for 3 roles:
Track in your role's order
Pick your target role and all 370 problems resequence to what that interview actually asks.
Start freeProblem set and role mapping as of .