Pergunta de entrevista da empresa 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?

Respostas da entrevista

Sigiloso

25 de jul. de 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

Sigiloso

24 de jul. de 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.