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

Why need sort?

- Anonymous December 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

For a given x you would look at the points that are in the range (x-5) to (x+5) thats why

- Rayden December 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

No sort requied.
(x1, y1)-->(x2, y2)-->(x3, y3) ....->(xn, yn)
First iteration, only check x, elimated points which x is not falling into [x-5, x+5]
Second iteration, only check y, eliated potins which y is not falling into [y-5, y+5]
For the left points, calc sqrt((x-xi)*(x-xi) + (y-yi)*(y-yi))], if the reslut <=5, keep the point, otherwise, remove it.

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

No sort requied.
(x1, y1)-->(x2, y2)-->(x3, y3) ....->(xn, yn)
First iteration, only check x, elimated points which x is not falling into [x-5, x+5]
Second iteration, only check y, eliated potins which y is not falling into [y-5, y+5]
For the left points, calc sqrt((x-xi)*(x-xi) + (y-yi)*(y-yi))], if the reslut <=5, keep the point, otherwise, remove it.

- Anonymous December 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

" Now for any given point" This explanation is vague but I would say this function will be called more than one time on the same set of points with the point changing. So yes sorting will benefit a lot if that's the case. Otherwise yes no need for sorting.

- Rayden December 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even if the point is changed, our program will eliminate the points based on the coordinates of the given point.

I believe there is no need of sorting. It will happen in O(N)

- Anonymous December 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Every time the point is changed you have to iterate through n items without sorting in your solution.

- Rayden December 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

fix the given point.
and draw a circle whose center=(given point) and r=5.
now check those points which lies with in the circle.
that will be the ans.

- psan December 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you have very few points ( i.e: 5) sorting solution would be bad than simply directly checking the distance of all points. Same applies for the circle solution. Its a very debatable question and I think it is not appropriate for a phone interview. But it would be for a on person interview.

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

If you have very few points ( i.e: 5) sorting solution would be bad than simply directly checking the distance of all points. Same applies for the circle solution. Its a very debatable question and I think it is not appropriate for a phone interview. But it would be for a on person interview.

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

i suppose points are given as Point(x, y). Now have a loop

while (n--)
{
if (abs (points[n].x - xx) == 5 && abs (points[n].y - yy) == 5)
{
cout << points[n].x << points[n].y;
}
}

// xx, yy are give points
// points is an array holding points.

complexity: o(n)

- Anonymous December 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Sort x coordinates using counting sort (O(n+k)).

Than for the given point and range find the distance of each element in that x range.

O(2n+k) (k is the range)

- Rayden December 07, 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