Challenge: Find Middle Node of Linked List

Here's another interesting coding challenge to test your knowledge on linked lists.

Problem Statement

You have to implement the findMid() function which is a member function of a LinkedList and it should return the value of the middle node. If the length of the list is even, the middle value will occur at length2\frac{length}{2}. For a list of odd length, the middle value will be length2+1\frac{length}{2}+1.


A linked list.


Middle element of the linked list.

Sample Input

LinkedList = 7->14->10->21->null

Sample Output


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