Microsoft Interview Question for Software Engineer / Developers






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

1. find where the slow and fast pointers meet.
2. split the LL at that point. So that the loop is removed and now the "6" becomes a "Y" (Think about it and convince yourself that it infact becomes a "Y"
3. Now it becomes a question of finding intersection point of the two LL's .
4. Once you find the intersecting point. Traverse both lists once each.
5. Length of the original LL = The uncommon nodes (from both the LL's) + common nodes counted only once (the tail of the "Y")
6. Join the split ends back together to get a "6" .

- googler August 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice solution, pretty nice

- Anonymous November 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

how will you find an intersection?

- job_hunter July 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

For Finding Intersection...
1. Bring back Slow pointer back to start of LL and let the Fast pointer be at same loaction where slow & fast meet.
2. Now increment both Slow and Fast pointer with same speed that by +1 node.
3 Again they will meet at intersection point now.

- XYZ October 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A few restrictions: Run time complexity is O (N) and memory has to be CONSTANT.

- blue June 20, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2 pointers
incr one by +1
incr other by +2
they will frist meet in N iterations

- Nitu June 21, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

when they meet after N iteration, (N+1)/2 will give the length of the stem

- saga June 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

2 pointers
incr one by +1
incr other by +2
they will frist meet in N iterations

- Nitu June 21, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2 pointers
incr one by +1
incr other by +2
they will frist meet in N iterations

- Nitu June 21, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the step here is to find the length of list. not to see whetehr circle s present.

- Vandna December 28, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use hashing for each node you traverse keep incrementing the node count. The moment the new node clashes in the hash table, you stop traversing and return the count. This has the execution time complexity of O(N) and the space complexity of O(N)

- Ravi January 06, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Question says memory has to be CONSTANT

- Anonymous November 23, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ravi. You approach only works when the shape is like 6 or 0.

It doesn't work for cases when the shape is like 8 or @.

However, I don't know if 8 or @ are valid cases. Or else, maintaining a hash for pointers will do.

Nil

- Nil March 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you can never have 8 in a single ll

- 8 August 18, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

dad

- asdasda August 18, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I believe if you straighten out @ then it will become a 6.. As far as 8 is concerned that's as good as 0

- Anonymous November 28, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry.. my bad.. did not understand the question completely..

- Anonymous November 28, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Length of such a list = Length of the loop + Length of the non-loop segment.

- Helper December 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You should not require to split the list. Although approach is same.
1) Find the intersection point. Say P1 is pointing to this node.
2) Start from the head till P1, count the nodes. let say it is P2.
3) Increment the P2 by 1.
4) Again run a loop till P2->next = P1. And keep on updating the count.

- Piyush Beli March 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Have a flag in the node, set it to true once you visit it and increment the counter.
Finally the counter is the size of the list!!

- sathishp123 April 25, 2012 | 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