 All Problems
Middle of the Linked List
easy
linked list
two pointers
amazon
facebook
google

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.

Example 1:

Input:  1 2 3 4 5
Output: 3 4 5

(Middle is node 3)

Example 2:

Input:  1 2 3 4 5 6
Output: 4 5 6

(Two middles: 3 and 4, return the second)

Constraints:

  • The number of nodes in the list is in the range [1, 100]

Input format: Space-separated integers.

Output format: The middle node onwards.

Run to check your code against the sample cases, or submit to run every case