Middle Node of Singly Linked List

LINKED LIST

Problem

Given a singly linked list, this function returns the middle node.

If the list has an even number of nodes, it returns the second of the two middle nodes. The function navigates through the list to determine the middle node efficiently.

Examples

findMiddleNode([1,2,3]) // 2 // Why? The middle node of the list is node 2 findMiddleNode([1,2,3,4,5,6,7,8]) // 5 // Why? When there is 2 middle nodes (4 and 5), // we return the second one (5).
Loading...
1
2
3