Middle of Linked List Problem Statement
Given the head node of a singly linked list, return a pointer pointing to the middle node of the linked list. In case the count of elements is even, return the node which is further from the head.
Example:
Input:
1 -> 2 -> 3 -> 4 -> null
Output:
Pointer to node with value 3
Explanation:
The linked list has 4 elements, so we return the second of the two middle elements (i.e., node with value 3) as it is further from the head node.
Constraints:
1 <= T <= 50
1 <= N <= 4*104
-109 <= data <= 109
- The linked list nodes must not contain the value -1 (used only as a sentinel value for input parsing).
- Time Limit: 1 sec
Note:
- You do not need to print anything; just implement the function and return the answer.
- For a linked list with only one node, the head node itself is the middle.
- If no midpoint exists, return a null pointer.
AnswerBot
4d
Return the middle node of a singly linked list, or the second middle node if count is even.
Traverse the linked list with two pointers, one moving twice as fast as the other
When the fast pointer reache...read more
Help your peers!
Add answer anonymously...
Top Freshworks Senior Software Developer interview questions & answers
Popular interview questions of Senior Software Developer
>
Freshworks Senior Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app