Pinterest Interview Question for Software Engineer Interns


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 3 vote

Here is the method that I thought :
Maintain a sorted array of long//lat of all places, sorted first by longitude and second by latitude.
If we have to find all places from point (a,b) with in a radius of r.
1) find all the places within the longitude range a+r and a-r and latitude range b+r and b-r (Use Binary search on sorted array to find this range of places).
2) Now for these points use the expression (x-a)^2+(y-b)^2 -r^2 to decide whether they lie inside or outside the given radius.
a) if (x-a)^2+(y-b)^2 -r^2 > 0 it lies outside the given radius
b) if (x-a)^2+(y-b)^2 -r^2 < 0 it lies inside the given radius

- CodePredator May 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your method is same as calculating the distance between centre and the point and checking if it is < R

- DashDash May 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@codePredator. nice idea

- dadakhalandhar May 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

First calculate the distance between all the places with the centre i.e given longitude and lattitude.
Now whichever is equal to and less that the radius are the places needed

- DashDash April 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

u cant / shouldnt calculate distances between all places and the centre. have to be smart in selecting points to calculate the distances.
Precompute all points to a red black tree and then use that

- bbarodia April 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Precompute a grids from a fairly coarse to fairly fine resolution. When a search is made, choose the appropriate grid (based on the radius of the circle), and for the cell(s) that are inside the circle select the cells in subgrids which are part of the circle.
So for example, you might have the outer-most grid having cells which are 100x100km. If a search is made which goes across two of these cells, select both and then select the subgrids of size 50x50km, then the subgrids of 10x10km inside those until you get to the finest resolution. If the finest-resolution cell is completely inside the circle then select all places, else for those cells calculate all distances to the center (but there shouldn't be too many calculations since there will be relatively few fine-grained cells on the boundary, and relatively few places in each of those, as long as the grain is fine enough).

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

Quad Tree or KD tree

- Deepak October 16, 2013 | 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