Amazon Interview Question for Software Engineer / Developers






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

Do we've any more information, like, if the file data sorted or not; or, what is the range of numbers so on; or, does there any duplicate of any value/is each number unique (in either of the files)?

- anonymous August 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort the two lists using external merge sort , then based on the memory restriction for ex if 120 mb memory is allocated load 40mb of first list, 40 mb of second list and next 40 mb for intersection . use merge logic on list1 and list 2 and find common elements , if any of the lists are over load the remaining content in to the memory . if intersection memory becomes full write it to disk . In this way we can find out the intersection of two element array.

- codeninja August 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Calculate the length of both of the lists eg: a.length= l , b.length=m
2. If one list is greater than other calculate the difference in length
3. Traverse the bigger list to the diff = l-m/m-l distance
4. Then traverse both the lists ( in this case as codeninja specified traverse the lists in chunks depending on the memory) and find if two nodes intersect

The above algo takes O(l+m) There is no need to sort the lists. If they are arrays then its even better, you can skip the traversing of diff length

- San August 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I'm not sure what you are describing here. What do you mean "find if two nodes intersect"?

If the input is [1,2,3,4,5,9,11] and [2,4,5,6,11,22,33], then your output should be [2,4,5,11]

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

I guess I misunderstood the question as intersection of two singly linked lists, if the question was to find the common elements then sorting and merging would solve the problem

- San August 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Write a simple map reduce job.
Mapper: emit (element, 1)
Reducer: sum values and output if sum > 1.

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

I dont see Hadoop in question. still Amazon should welcome this solution

- n1k41| January 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Some points are not clear like what are the input to the function? An array or a linked list. What is the return type is it a linked list or an array??

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

// sort List1 and List 2 --> complexity = O(mlogm + nlogn)
int i, j;
i = 0; i = 0;
while(i < size of List1 and j < size of List 2)
{
if(A[i] == A[j])
{
print(A[i])
}
else if(A[i] > A[j])
{
i++;
}
else{
j++;
}
}

- Anshul Zunke August 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Create a hash table from the first list
2. Loop through second list and check if there is corresponding available value.
--> O(m+n)

For the memory limitation, thinking ...

- fffan August 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Create a B+ Tree from List1, where each leaf is different file(As the list is very large, and can't loaded to whole list to memory at once).
2. For each element in List2, seach it from B+ tree(which is of List1).

T = O(M*Log(N)(of base k) + N*Log(N)(of base k).

N: Number of elements in List1.
M: Number of elements in List2.
k: B+ Tree is k-way tree.

- SRB August 31, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Sort both arrays. If the arrays are from huge file sort the file using external merge sort.

2. In a single loop, read contents from each array and find the intersection using the simple algorithm below:

int a[] = {1, 3, 4,5,8,9, 9, 11};
int b[] = {3, 5, 6, 9, 9, 11, 23};


for(int i=0, j=0; i<a.length && j<b.length;) {
if(a[i] == b[j]) {
System.out.println(a[i]);
i++;j++;
}else if(a[i]<b[j]) {
i++;
}else {
j++;
}

}

- Philip August 31, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't think any other solution exists.

- ACP Pradyuman September 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I dont think job exists!

- Anonymous January 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Does anybody know what is map reduce?

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

lols... don't you know HOW TO SEARCH ON GOOGLE :d ?

- anonymous September 02, 2011 | Flag


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