## Riverbed Interview Question for Software Engineer / Developers

Country: United States

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

You can use the Cycle Detection Algorithm (in particular, I like the Tortoise and Hare Algorithm). Look it up on Wikipedia.

The basic idea is to have 2 pointers: one slow and one fast... both start at the head of the list. The slow pointer moves one step at a time and the fast pointer moves 2 steps at a time. If they meet at any time ie.,e if slow == fast, there is a loop in the list...

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

By traversing using two pointers, in every iteration, first pointer will advance by one node and the, second will advance by two nodes. When two pointers matches (i.e. pointing to the same node), you can say their is a loop.

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

2nd way is to use hashtable, not good way as Tortoise and Hare Algorithm

Create hashtable and start pulling item from linkedList one-by-one and put it inside hashtabe. Before putting it check if it is exist in hashtable, if yes, then you are done. You came to the object where cycle started.

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

This does not take care of the case where the list might containt duplicate elements...

consider the case: 1-> 2->3 -> 4 -> 3' (a new 3)
this list does not contain a loop

consider the case: 1-> 2-> 3 -> 4 -> 3' (new 3) -> 5-> 3 (first 3)
this list does contain a loop.

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

this depends on what inside the list,
if coding in java then it really depends on equal+hashcode implementations. if it is just primitive types like int then u are right.

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

reverese the linkedlist twice, and then compare. If this list is same, then it has a loop.

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

how will you reverse a circular list?

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

How will u reverse a circular list?

Name:

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

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### 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.