Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
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.
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.
" 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.
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)
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.
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.
Why need sort?
- Anonymous December 07, 2011