Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Step1:- Find the lenght of both linklist.
let say m&n
Step2:- Now move the pointer of larger linklist by |m-n| node..

Step3:- Be sure pointer of smaller one is on head node & now move the pointer of both linklist.& check for the common address.

- Anonymous May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the length of two linked list are same??

- soni May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the length of two linked list are same??

- soni May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the length of two linked list are same??

- soni May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the length of two linked list are same??

- soni May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the length of two linked list are same??

- soni May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

then, you can just skip the step 2.

- lee May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

then, you can just skip the step 2.

- lee May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

then, you can just skip the step 2.

- lee May 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

wont we be required to check the nodes which we are directly skipping .... what if they are merging at the first node itself

- student June 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good point

- m.b June 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Go to the last node in one list say its e, and go through another list check if the next point to the e. Also check if e point to head of another list. If match, then they are merged. This is O(n+m).

not sure how to find merge point efficiently, can do binary search on smaller list if its merged.

- jcf May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just one thing, you need not check where node 'e' points to, as it is the last node.

- devesh chanchlani May 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You don't even know then is " end" for the linked list. It might be cyclic.

- Leon May 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

There's no point merging a cyclic list to other, resulting structure wont be a list

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

Step1:- Find the lenght of both linklist.
let say m&n
Step2:- Now move the pointer of larger linklist by |m-n| node..

Step3:- Be sure pointer of smaller one is on head node & now move the pointer of both linklist.& check for the common address.

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

Step1:- Find the lenght of both linklist.
let say m&n
Step2:- Now move the pointer of larger linklist by |m-n| node..

Step3:- Be sure pointer of smaller one is on head node & now move the pointer of both linklist.& check for the common address.

- Ap May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Step1:- Find the lenght of both linklist.
let say m&n
Step2:- Now move the pointer of larger linklist by |m-n| node..

Step3:- Be sure pointer of smaller one is on head node & now move the pointer of both linklist.& check for the common address.

- Ap May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Step1:- Find the lenght of both linklist.
let say m&n
Step2:- Now move the pointer of larger linklist by |m-n| node..

Step3:- Be sure pointer of smaller one is on head node & now move the pointer of both linklist.& check for the common address.

- Ap May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Step1:- Find the lenght of both linklist.
let say m&n
Step2:- Now move the pointer of larger linklist by |m-n| node..

Step3:- Be sure pointer of smaller one is on head node & now move the pointer of both linklist.& check for the common address.

- Ap May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what if the length of two linked list are same??

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

Step1:- Find the lenght of both linklist.
let say m&n
Step2:- Now move the pointer of larger linklist by |m-n| node..

Step3:- Be sure pointer of smaller one is on head node & now move the pointer of both linklist.& check for the common address.

- Ap May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I gave an approach using hash map. loop through one list and insert it into HashMap. Then loop through another list and try to retrieve from HashMap. HashMap returns a common node if one present. else return null.

- KSS May 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

another approch to this problem
just traverse both list and put element in two different stack.then start poping element from both stack one by one and check the element,do this until u havent got the unequal element.the answer will be the last match element..

- jai May 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Instead of element check for node address. Element value can be same for different node.

- Sanjay Kumar May 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is this a trick question? In order for two singly linked list to merge/meet at a node, all nodes after the meeting node must be identical as well, which means they must have the same tail node as well (my definition of a tail node is one that has no trailing node). Many linked lists implementations already keep a pointer at the tail, so the access time is O(1) to compare if two lists have merged. If so, traverse backwards until we find the node where they diverge and that's where we stop. In worst case, it's O(n), best case O(1).

- Chris November 03, 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