← Cisco questions
CodingReported in a candidate post, Jul 2025

Find the middle node of a linked list

Filed under Cisco · Also reported at Adobe, Goldman Sachs

Free read 2 of 3

Confirm 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

  1. Confirm how ties are handled for even-length lists (usually return the second middle node).

Solution

O(N) time, O(1) space

Python
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.