By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
(Complete Guide for FAANG-Level Interviews)
"This problem appears in 1 out of every 3 onsite interviews—nail it, and you prove you can optimize traversals, handle edge cases, and think in two-pointer patterns—skills every FAANG interviewer tests."
Before tackling this problem, ensure you understand: 1. Singly Linked List Basics – Node structure (val, next), traversal, and edge cases (empty list, single node). 2. Two-Pointer Technique – Fast and slow pointers (e.g., cycle detection in linked lists). 3. Time/Space Complexity – Big-O notation for linked list operations.
val
next
current.next
None
head is None
head.next
Mental Checklist for Every Linked List Middle Problem:
[1,2,3,4]
2
3
Confirm: "What should I return for an empty list or single-node list?" (e.g., None or head?).
head
Choose the Technique
Recursion → Only if explicitly asked (O(n) space for call stack).
Initialize Pointers
slow = head
fast = head
If using a dummy node: dummy = ListNode(0, head), then slow = fast = dummy.
dummy = ListNode(0, head)
slow = fast = dummy
Traverse the List
While fast and fast.next are not None:
fast
fast.next
slow
slow = slow.next
fast = fast.next.next
Handle Edge Cases
Even-length list: Return slow (first middle) or slow.next (second middle).
slow.next
Validate the Solution
Test with:
[1]
1
[1,2]
[1,2,3,4,5]
Optimize for Follow-Ups
Problem: Given a singly linked list, return the first middle node (for even length, return the left middle). Example: [1,2,3,4,5] → 3; [1,2,3,4] → 2.
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
Problem: Return the second middle node for even-length lists. Example: [1,2,3,4] → 3.
def middleNodeSecond(head: ListNode) -> ListNode: slow = fast = head while fast.next and fast.next.next: slow = slow.next fast = fast.next.next return slow.next if fast.next else slow
Problem: Delete the middle node of a linked list. If the list has even length, delete the second middle. Example: [1,2,3,4] → [1,2,4].
[1,2,4]
prev
prev.next = slow.next
def deleteMiddle(head: ListNode) -> ListNode: if not head or not head.next: return None slow = fast = head prev = None while fast and fast.next: prev = slow slow = slow.next fast = fast.next.next prev.next = slow.next # Delete the middle node return head
while fast.next
while fast and fast.next
None.next
if not head: return None
deleteMiddle
"Alright, let’s lock this in. To find the middle of a linked list:
This pattern is a classic—it’s O(n) time, O(1) space, and shows you can optimize traversals. Practice it until it’s muscle memory. You’ve got this!
Now go crush that interview! ?
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.