Pergunta de entrevista da empresa Microsoft

finding a missing number in a continuous number sequence.

Respostas da entrevista

Sigiloso

25 de mar. de 2011

Should be O(logN)

1

Sigiloso

13 de jul. de 2011

It is not possible to have the solution in O(log N) time because we are not exactly sure about which value we are looking, So a binary search is meaningless. As for the last solution, why should we even try and find a sum and deduct etc. That would be more work than necessary. Also, a contiguous sequence can be A.P, G.P or anything, so a way to do this would be to iterate over the array, predict the next value, and then check if the current value in array is same as the predicted value. If they are same, move to the next element, else we found the misssing element. It will be an O(N) solution.

2

Sigiloso

28 de set. de 2011

Jack's answer is the most appropriate since it is not stated that the numbers are in sorted order. If the numbers are sorted Ravi has the best answer.

Sigiloso

26 de mar. de 2011

just iterate from the list and add for the numbers. Also the sum of first n numbers is n(n+1)/2. Minus this with the total you got by iterating all the numbers. this is the number. its complexity is O(n)

Sigiloso

25 de mar. de 2011

binary search, to see if you given index value matches the number in that position, if not, focus right half, else, focus left half, and do it recursively until get the position of missing value. O(NlogN)