Find Middle of Linked List

Given the head node of a singly linked list, your task is to return a pointer pointing to the middle node of the linked list.

When the number of elements is odd, return the middle element. In the case of an even number of elements, return the one which is farther from the head node.

Example:

Consider the linked list: 1->2->3->4->null

Input:
head = [1, 2, 3, 4, -1]
Output:
Node with value 3
Explanation:

The linked list has 4 nodes, so there are 2 potential middle nodes (2 and 3). We select 3 because it's farther from the head node, which is 1.

Constraints:

  • 1 <= T <= 50 where T is the number of test cases.
  • 1 <= N <= 4*104 where N is the number of nodes in the linked list.
  • -109 <= data <= 109 for each node value.
  • Node values are not equal to -1.
Note:
1. You are not required to print anything; simply implement the function to return the pointer.
2. If the linked list has a single node, return the head node as the middle.
3. If there is no distinct middle (for empty lists), return a null pointer.
AnswerBot
4mo

Return the middle node of a singly linked list, selecting the one farther from the head node in case of even number of elements.

  • Traverse the linked list using two pointers, one moving twice as fast as...read more

Help your peers!
Select
Add answer anonymously...

Accenture Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked 2w agoQ. Which technology stack have you worked with?
An Associate Software Engineer was asked 3w agoQ. What is NLP?
An Associate Software Engineer was asked 4w agoQ. Explain the concepts of OOPs.

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked 2w agoQ1. Which technology stack have you worked with?
An Associate Software Engineer was asked 3w agoQ2. What is NLP?
An Associate Software Engineer was asked 4w agoQ3. Explain the concepts of OOPs.

Top HR questions asked in Accenture Associate Software Engineer

An Associate Software Engineer was asked 2w agoQ1. Have you ever encountered a project issue with a teammate who unexpectedly left,...read more
An Associate Software Engineer was asked 2w agoQ2. Can you share something about yourself that is not included in your resume?
An Associate Software Engineer was asked 1mo agoQ3. What challenges did you face as a team leader during the project?
Accenture Associate Software Engineer 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