Pergunta de entrevista da empresa Amazon

find the closest pair of points in a 2 dimensional space.? write an algorithm.

Respostas da entrevista

Sigiloso

10 de fev. de 2012

Answer to your question. "1) How would you find a number which is repeated odd number of times in array of number where every other number is repeated even no of times.? " Soln: 1) Use XOR operation 2) for example, 1 ^ 1 =0. So if any number is repeated even number of times it is zero. 3) If a number is repeated odd number of times say 3 times then a) 3^3 =0 b)0^3=3. int XOR=array[0] for(int i=1;i

Sigiloso

10 de fev. de 2012

find the closest pair of points in a 2 dimensional space.? write an algorithm.? This is typical computational geometry. To find a closest point, use the pigeon hole principle and this will bring down computational time to O(n* logn).