Nextag Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




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

If points given in random order, you can't solve this problem faster than O(N), because you should look at each point at least once, so you have to go through all the points and check distance between it and A

- V.Krestyannikov January 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

en.wikipedia.org/wiki/K-d_tree#Points_only_in_leaves
As said in above link, if the points are distributed randomly all across the space, we can do better than linear time with hacking around using method in the link.

PS: This may even qualify as a point-in-a-polygon variant and I'm not sure of its complexity.   I'm off to flight now but will let you know if we can use this techinique as well.

- AmzFAILFacebookFailMSFTFail January 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It's not exactly true, because before you start to answer queries, you should build k-d tree, and it takes O(N log(N)) time, and after that each query will take O(logN) time.

- V.Krestyannikov January 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This algorithm will be useful when there is one set of points and a lot of queries and the resulting complexity will be O(Q logN) where Q is number of queries, N is number of points.

- V.Krestyannikov January 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes! Initial k-d tree building takes O(NlogN). But I'm sure mentioning that k-d tree can be used in this kind of situations and discussing its pros and cons will sure get you extra credit in interview :-)

- AmzFAILFacebookFailMSFTFail January 06, 2012 | 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