Return the middle node of a singly linked list. If there are two middle nodes, return the second one.
Given the head of a singly linked list, return the node that appears in the middle of the list.
If the list has an even number of nodes, there are two middle nodes. In that case, return the second middle node.
The answer should be the node itself, not just its value.
Find the middle of the list efficiently, ideally in one pass.
Example 1
Input
head = [1,2,3,4,5]
Output
[3,4,5]
Explanation
The list has 5 nodes, so the middle node is 3.
Example 2
Input
head = [1,2,3,4,5,6]
Output
[4,5,6]
Explanation
The list has 6 nodes, so there are two middle nodes: 3 and 4. Return the second one, which is 4.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.