Pregunta de entrevista de Microsoft

Problem: Array of 100 integers between 0 and 100. One integer is doubled, find out which. Question: Which methods exist and how do they compare?

Respuestas de entrevistas

Anónimo

25 jul 2013

sum on N numbers in (N*N+1)/2. Add all the numbers and find out how much it differs from this sum

2

Anónimo

24 jul 2013

The worst answer in this case is an algorithm, the interviewer clearly did not ask for that. An important question to ask is whether they want the Position of the doubled integer or only its value. Possible solutions: sort (quick sort, radix-sort/K-sort), search, counting, Polynom, a[0]+a[1]+...a[101] - 0+1+2+99+100 = doubled integer.