nterview: Remove Loop in linked list – Java

 

http://stackoverflow.com/questions/5607292/interview-remove-loop-in-linked-list-java

I was asked this question in interview: “How to detect the loop in linked list?”, I solved this but immediately the interviewer asked me how do I remove the loop in a linked list. I fumbled.

So any pointers on how to solve this, may be pseudo code, or method definition?

I’m comfortable with Java so I have tagged this question under java.

For Instance this linked list has a loop
0—>1—->2—->3—->4—->5—->6
                  ▲                 |
                  |                 ▼
                 11<—-22<—-12<—-9<—-8

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s