Find the middle node of a linked list
Filed under Cisco · Also reported at Adobe, Goldman Sachs
Free read 2 of 3Confirm how ties are handled for even-length lists (usually return the second middle node).
The question
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.
Constraints
- The number of nodes in the list is in the range [1, 100].
- 1 <= Node.val <= 100
Examples
- Input
- head = [1, 2, 3, 4, 5]
- Output
- [3, 4, 5]
- Why
- The middle node of the list is node 3.
- Input
- head = [1, 2, 3, 4, 5, 6]
- Output
- [4, 5, 6]
- Why
- Since the list has two middle nodes with values 3 and 4, we return the second one.
Approach
Confirm how ties are handled for even-length lists (usually return the second middle node).
Traverse the linked list once to count the total number of nodes, then traverse a second time up to length / 2 to find the middle node.
Use the Tortoise and Hare algorithm. Initialize two pointers (slow and fast) at the head. Move slow by one step and fast by two steps. When fast reaches the end, slow will be at the middle.
Empty list (if allowed), single node list, and two-node list.
Solution
O(N) time, O(1) space
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def middleNode(head: ListNode) -> ListNode:
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
return slow
Tips
- What they are testing: Test with lists of odd lengths, even lengths, and a single node to verify pointer bounds.
- Common mistake: Failing to handle the single-node case or mismanaging pointer updates causing infinite loops.
Related Cisco questions
Collected from public candidate posts and coding forums. Updated Nov 2026.