Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Walk second list and insert all elements in a hash.
Walk first list and if an element is already in hash it is the common element.

- Anonymous October 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is if the lists are unsorted, as I think they are. You could do it without extra space in O(n) if the lists were sorted.

- eugene.yarovoi October 31, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

1) Find lengths of two linked list O(n1) + O(n2)
2) Find the long list and skip the (long list length - short list length) nodes
3) Now walk the two linked lists together (in parallel one step/move-next at a time), and compare the values of two nodes (just compare node address if the lists are already joined). Return the node value/address where the euality check succeeds. O(min(n1, n2))

- Anonymous November 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

???

Why would you blindly skip nodes in the longer list? The question asks you to look for the intersection between the two lists. What guarantee do you have that the first (LongerList.Count - ShorterList.Count) Nodes in the LongerList are going to be non-intersecting elements?

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

Because when intersection point is somewhere after these nodes only. like 1-2-3-4-5 and 3-4-5. first 2 nodes can be skipped.in a Y shaped intersection.

- Amol November 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

cant it be like 1-2-3-4-5 and 1-2-3. it's still a Y shaped intersection

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

List1.Intersect(List2).First();

Of course that's not an acceptable answer.
So sort the lists
Insert elements of one list into a HashTable.
Walk the second list and check each element to see if it's in the HashTable.
Return the first or null.

- Anonymous November 02, 2011 | 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