## Amazon Interview Question for Software Engineer / Developers

• 0

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.

Comment hidden because of low score. Click to expand.
0

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.

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))

Comment hidden because of low score. Click to expand.
0

???

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?

Comment hidden because of low score. Click to expand.
0

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.

Comment hidden because of low score. Click to expand.
0

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

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.

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.

### 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.