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

- JustCoding September 27, 2012 | Flag Reply
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.

- sahaj September 27, 2012 | Flag Reply
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.

- kamoliddin September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- JustCoding September 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- kamoliddin September 27, 2012 | Flag
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.

- chira August 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

how will you reverse a circular list?

- coder March 07, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How will u reverse a circular list?

- coder? March 07, 2015 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More