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
4mo

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!
Select
Add answer anonymously...

Top Senior Software Developer Interview Questions Asked at Freshworks

Q. What is threading, and what are the different scheduling algorithms?
Q. Cube Sum Pairs Problem Statement Given a positive integer N, find the number of ...read more
Q. Can you discuss the low-level design (LLD) of a system similar to Flipkart?
Senior Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits