Middle of the Linked List
Module 7 · Linked Lists
Problem
Given the head of a singly linked list, return the middle node. If there are two middles (even length), return the second one.
Examples
Example 1
Input
head = [1,2,3,4,5]Output[3,4,5]Example 2
Input
head = [1,2,3,4,5,6]Output[4,5,6]Explanation. second middle
Constraints
1 ≤ length ≤ 100.
Attempt it first
Two passes (count, then walk half) is correct and worth 30 seconds. The lesson-worthy version is one pass — the runner from the surgery lesson. Work out for yourself where slow lands for BOTH parities before opening the solution; the even case is where implementations differ.