Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Make min heap of 100 elements.

Whenever new incoming number is less than the top of heap ignore it.
Otherwise replace top with this new number and bubble down this number to its correct position by calling heapify.

- Nitin Gupta January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hello.. i am not clear with ur idea.. can u explain it more. Min heap will be applied to the whole integers and how to find the first 100 integers..
Thanks in advance

- Kannan S January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

As it seems to me, question itself is ambiguous. What is meant by first 100 large numbers. As per my understanding, it should be find 100 large numbers.

So we can create min heap of 100 elements size. As soon you receive number from the stream, put it in heap and heapify.

- Nitin Gupta January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I understand the question in a different way. There are stream of n integers and u r asked to print first 100 large numbers.

Use quick sort to get the 100 the number say x from the array O(n) and display the numbers which are <=x.O(n)

max = ans(a[],lower,upper,n) O(n)
print(all nos <= max in array) O(n)


ans(a[],lower,upper,n)
{
while(upper>= lower)
{
int i= spilt(a[],lower,upper,n); split function is Quick sort operation
if(i==n)
return a[i];
if(i<n)
{
upper=i+1;
n=n-i;
}
if(i>n)
{
lower=i+1;
n=n-i;
}
}
}

- kannan s January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
4
of 4 vote

Do bubble sort for 100 times.. and get the first 100 elements in the array.. Time complexity will be O(100n) = O(n). Space complexity will be O(1).

- Kannan S January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

lol

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

Can you give more details ...or example

- Ganesh January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

eg: 1, 12, 13, 23,11,20,45,67,23.........
eg: we need first 4 largest
result : 1,12,13,2...when we read 23 then it has to delete the least one in the result and to accommodate the latest one
result after removing one : 12,13.2,23...so on

- Minnu January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can create a min heap of size 100 .pick the element from stream and put in Min heap when the 101 th element pick from stream find the minimum element of min heap ,if it is large ,then remove that min value and again arrange the heap.

- Raj January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Quick selection to pick 100th max number, e.g. A , then iterate array and take all number > A, and count them, if less than 100, say n, then repeat 100-n for A, should be O(n).

- Anonymous January 08, 2013 | 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