Evalueserve Interview Question: How would you traverse a link... | Glassdoor.co.in

Interview Question

Research Associate Interview Gurgaon, Haryana

How would you traverse a linked list with n objects in such

  a way that you reach the middle of the list in less than n iterations?

Interview Answer

1 Answer


We use 2 pointers, increment pointer (p1) by 1 and the (p2) by 2. When the p2 reaches the end of the list then p1 is on the middle element of the list.

Interview Candidate on 07-Aug-2011

Add Answers or Comments

To comment on this, Sign In or Sign Up.