Middle of the Linked List - Problem

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.

Input & Output

Example 1 — Odd Length List
$ Input: head = [1,2,3,4,5]
Output: [3,4,5]
💡 Note: The middle node is 3. Since there's only one middle node in odd-length lists, return node 3 and all nodes after it.
Example 2 — Even Length List
$ Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
💡 Note: There are two middle nodes (3 and 4). Return the second middle node (4) and all nodes after it.
Example 3 — Single Node
$ Input: head = [1]
Output: [1]
💡 Note: Only one node exists, so it is the middle node.

Constraints

  • The number of nodes in the list is in the range [1, 100]
  • 1 ≤ Node.val ≤ 100

Visualization

Tap to expand
Middle of Linked List: [1,2,3,4,5] → [3,4,5]Input:12345Middle Found:345Output: [3,4,5]
Understanding the Visualization
1
Input
Linked list [1,2,3,4,5]
2
Find Middle
Use fast/slow pointers to locate middle
3
Output
Return middle node and all following nodes
Key Takeaway
🎯 Key Insight: Fast and slow pointers eliminate the need to count nodes first
Asked in
Google 25 Amazon 20 Microsoft 15 Apple 12
425.0K Views
High Frequency
~10 min Avg. Time
8.5K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen