Amazon Interview Question for Software Engineer / Developers






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

just curious is this for java programming position? or c/c++?

- Anonymous May 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

was it a onsite or telephonic question ?

- Anonymous May 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can do this in several ways.
1. Sort all points by distance from given point and take first k - O(NlogN)
2. Use min heap of size k push all points there. Track the size of heap, remove the last element when size of heap is k+1. This will work at NlogK.

- gevorgk May 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nice Methods gevorgk!
How about using something like interval trees (augmented BST)?

- Anonymous May 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function findKclosest(point x, point A[], int n)
{
    MAX-HEAP m = new MAX-HEAP(A[1...k])
    MAX = m.GetMax();

    for(c = k+1 to n)
    {
       if(Distance(A[c] < MAX) 
       {
           m.RemoveMax();
           m.Insert(new Node(A[c], distance(A[c], x));
           MAX = m.GetMax();
       }
    }
  
 m.Print();   
}

even though it's O(nlog k) in theory, it performs better in practice (depending upon the distribution of points) because I compare against a MAX variable instead of getting the MAX from heap every time.

- drekhi May 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Syntax error in if(Distance(A[c] < MAX) :)

- Muk May 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I believe it's solvable in O(n) time using linear time order-statistic computation.
steps:
1. compute D(i) = distance of point i from p; for 1<=i<=n
2. find k-th order statistic in O(n) time. let this is point q. [REF: CORMAN book]
3. select all points r such that Distance(p,r) <= Distance(p,q).

Each of steps 1-3 takes O(n) time. So total time is O(n).

- dejected May 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you put some highlight or give some linke to
"find k-th order statistic in O(n) time. let this is point q. [REF: CORMAN book]"

- Anonymous June 10, 2010 | 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