Pregunta de entrevista de IBM

You have an unsorted array of numbers from 0-100 except one number is missing. Write an algorithm to find the missing number.

Respuesta de la entrevista

Anónimo

7 nov 2016

Sort and traverse until you find gap of over 1: O(nlogn) Bitarray of 100 numbers: O(n) time but O(n) extra space Summing all the numbers to S' and comparing this to full sum S appears to be the best solution as it gives linear execution time: Missing Number = S-S'