Challenge: Middle of the Linked List

Try to solve the Middle of the Linked List problem.

We'll cover the following

Statement

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. This happens when the length of the list is even, and the second middle node occurs at length2\frac {length}{2}. Otherwise, if the length of the list is odd, the middle node occurs at length2+1\frac {length}{2}+1.

Constraints:

Let n be the number of nodes in a linked list.

  • 11 \leq n 100\leq 100
  • 11 \leq node.data 100\leq 100
  • head \neq NULL

Examples

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.