Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Should use kd-tree

- struggleyb February 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what would be the used k?

- Ali.Nour86 February 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

here k=2.
kd tree =k dimensions tree..

- bharat February 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Traverse through the list of points<lat, long>, calculate euclidean distance from given point and maintain a max heap of size 'k' where 'k' is the number of closest points we are expected to return. If, the heap_size is < 'k' just append new element to heap, else compare with max-heap root. if the new point is closer than farthest seen so far replace it with the new point seen and max-heapify.

- Second Attempt February 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

If 'World' list contains all possible lat/long values then what is the point of finding nearest lat/long points. We can find matching lat/long points ryt.. And also what do u mean by 'nearest'??

- PraveenBilla February 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

And also ArrayList can take only one object, I didn't get ArrayList<latitude,longitude>...

- PraveenBilla February 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

This is basically a K-nearest neighbours search .
Build a tree as in K-d algorithm on world's long/lat arraylist.
when an amazon long/lat point is given, search for that element in tree and find K nearest neighbours.

- bharat February 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't know if I understood it correctly, but I would suggest the following. First: What's the nearest location regarding two amazon stores? I would say, it's the way coming from one store to the other crossing this special location, with the minimum cost. So it's A1 -> ...-> P ->... -> A2 (A1 = 1st Amazon store 1, A2 = 2nd Amazon store, P = a location which has the feature, that cost(A1->P) + cost (P -> A2) is minimum). Whereby cost is the distance between to locations.

To do this, we use the ArayList "world" to build up a graph.
The elements of ArrayList "amazon" has to be a sub amount of ArrayList "world".

Since we don't know P, we should find the minimum way between A1 and A2 (e.g. by Dijkstra algorithm). If we cross one further position (which is an element of the ArrayList "world") we have the nearest place regarding two amazon stores. If we cross multiple Locations, those are equally nearest two those two amazon stores.

- sheena February 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Addition: If we find a direct connection between A1 and A2, we have to find the 2nd longest way by "earasing" the connection between those two stores.

- Sheena February 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

consider latitude and longitude as co-ordinates on 2D plane..
now it becomes simple..

A point-quad tree(refer wikipedia for "quadtree") will give the answer..
you can find the nearest shops in whatever direction(north-east(NE),NW,SE,SW) you want

- yKumar February 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

A node of a point quadtree is similar to a node of a binary tree, with the major difference being that it has four pointers (one for each quadrant) instead of two ("left" and "right") as in an ordinary binary tree. Also a key is usually decomposed into two parts, referring to x and y coordinates. Therefore a node contains following information:
4 Pointers: quad[‘NW’], quad[‘NE’], quad[‘SW’], and quad[‘SE’]
point; which in turn contains:
key; usually expressed as x, y coordinates
value; for example a name

- yKumar February 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is my approach , given the longitude and latitude of an amazon store , we need to sort
the other list using the distance as for comparision, this sort can be done in nlogn time.

- goutham467 February 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

why cant we make a two dimensional array and use distance formula between two co ordinates x1,y1 to x2,y2 as root((x2-x1)^2+(y2-y1)^2) to find ?

- sbharathind February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can make a matrix where col defines all amazon centers and rows all world.
Now calculate distance for each. Now for every row find k smallest values.

- DashDash February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can convert these two string into char arrays and sort them individually, run the loop till the size of the sort array and compare the starting elements of each array till the size of shortest array, if found any matching element do not add it to the new array else add it and convert that array into string again.

- Sushant February 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is the def of nearest?

- rbsomeg February 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

actually assume latitude,longitude be (x,y) now the question becomes finding nearest points(world) to a point(amazon) in two dimension this is simple , make two new array list of world one sorted according to x and another sorted according to y , take a point from amazon using binary search on these two list find four nearest points two according to x two according to y then find cartesian distance from all four points give the minimum .

- rdx February 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't think it's right. say the store is at (0,0)
you have world points(1,10),(2,20),(10,1),(20,2),(3,3)
are you suggesting the four nearest points are the first four?

- zyfo2 February 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

we can actually store the distance between each store point with the world point in a matrix. Now finding k shortest distance in a matrix is easy

- DashDash February 09, 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