## Yahoo Interview Question Software Engineer / Developers

• 0

Find if a singly linked List has loop or not.

How to find out middle element from a looped single linked list

Comment hidden because of low score. Click to expand.
0
of 0 vote

run three iterators with different speeds : 1x, 2x, 3x
(1+2)meeting means - we have a loop, and they have to stop on first element (so you could calculate a lopop size and move to mid point).

Comment hidden because of low score. Click to expand.
0
of 0 vote

1x and 2x will meet if there is a loop. When they meet again, 1x runs the loop length L from the first meet point. now run 1x,2x and 2x-L from the start. when 2x and 2x-L meet, 1x is at the mid point.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Can n e 1 plz explain how to get the midpoint....??

Comment hidden because of low score. Click to expand.
0

Have two pointers as slow and fast.
slow -> next
fast -> next.next

when fast reaches the end of the node, then slow will be in the middle.
Please refer to Floyd cyclic detection algorithm, the same algorithm is used for cycle detection as well.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.