Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

1. I think you can use Max Heap with K element to solve it easily, you just need maintain 10 element array, say:
Class Point
{
double x,y,z;
}

Point MaxHeap[k];

Complexity n*logk;

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

I think we can use Min Heap and key = x * y * z
Am I right ?

- arulece06 October 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think we can use Min Heap and key = x * y * z
Am I right ?

- arulece06 October 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i would say, use a min heap to store the data
first of all, initialize the min heap with 10 pts(x,y,z)
then from the 11th point and onwards, check the pt with the root of the heap, if it's smaller than the root, do nothing, else, replace the root the pt, and reheapify the min heap.

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

Basically you are storing 10 points. To find the largest element in an array and replace it O(10).

So the solution that you suggested to find k closest to origin is O(n*k).

For k = 10.. it is O(10n) ~ O(n)

But for very large k ... k = n / 2 or something

it is O(n * n / 2 ) ~ O(n^2)

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

Could we find a better solution w.r.t to time complexity for the second part -> finding the k co-ordinates nearest to the origin?
Someone suggested that k = n / 2. That could be true and worst could k=n...i.e finding and storing all the points.Hence n/2 = (1/2 * n). Or it could n itself. If so, removing the constant (1/2) it would O(n square)

- Anonymous October 23, 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