Finding middle element in a linked list - leetcode

Leetcode 876. Middle of Linked List

Link:

Middle of the Linked List - LeetCode

Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle…

leetcode.com

Description

Given a non-empty, singly linked list with head node head, return a middle node of linked list.

If there are two middle nodes, return the second middle node.

Note: The number of nodes in the given list will be between 1 and 100.

Find the middle of a given linked list

Given a singly linked list, find the middle of the linked list. For example, if the given linked list is 1->2->3->4->5 then the output should be 3.
If there are even nodes, then there would be two middle nodes, we need to print the second middle element. For example, if given linked list is 1->2->3->4->5->6 then the output should be 4.