Microsoft Interview Question for Software Engineer in Tests


Country: United States
Interview Type: In-Person




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

count nodes of both the list , say it be x & y. deduct the lesser from higher one say it be "N".
Now in the longer link list traverse N nodes.
Now start moving both the list one node at a time and compare. you will get the joint.

- Anonymous February 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is simple, and I believe it was answered before.
If the 2 lists merge, this means they have at least one common node.

The algo is simple, as follows:
say listA is size N and listB is size M (in example above N=4 and M=6).
Now, skip the first M-N elements from the longer list (in our case it's 2).
Then start comparing node by node, basically compare first element in listA with third element of listB. If it's same node, voila, you found the result, otherwise move to next item in both lists and compare them (in our example next will be second element in listA and fourth element in listB).

- amustea February 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

assume if list is
A->B->C->D
and second one be
A->B->C->D->E->F

now if I am getting it right what you would do is you will compare the first element A with C of second list and continue and we will never find the same A->B->C->D in second list..
Am i getting your solution wrong ?

- Aayush February 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@aayush
are the examples you have quoted, merge lists. Those two nodes are merge lists.
( Find the merge node of two linked lists where the rest of the nodes are same? is it correct meaning of the question, sorry if i am wrong)

@amustea, The assumption you made is both lists are unique. Is it a correct assumption. what if the lists are
A->B->C->D->C->D->E and
C->D->E

- SantiagoYMG March 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I must be missing something.

I see this question no different than asking - Find a node in a linked list.
The node to be found is head node of the smaller list.

The trick is that - there may be more than one A (head nodes) - and hence the comparison-traversal of the smaller linkedlist will be required to declare its a merge point.

- Ketan February 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not 100% sure what's the definition of "merge node". From my point of view, this problem is just another version of what KMP resolves.

- Jiaozi March 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Create a circular List of one of them.
2.Then try to find start of loop in Linked List.
3.This node would be their merge point.
4.Now restore the List.

- Vishal S Kumar December 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ya

- Anonymous May 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What if size of lists has not be given ?

- shashank June 01, 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