The common interview problem of determining the missing value in a range from 1 to N has been done a thousand times over. Variations include 2 missing values up to K missing val
My question is that seeing as the [...] cases converge at roughly something larger than O(nlogn) [...]
In 2011 (after you posted this question) Caf
posted a simple answer that solves the problem in O(n)
time and O(k)
space [where the array size is n - k
].
Importantly, unlike in other solutions, Caf's answer has no hidden memory requirements (using bit array's, adding numbers to elements, multiplying elements by -1
- these would all require O(log(n))
space).
Note: The question here (and the original question) didn't ask about the streaming version of the problem, and the answer here doesn't handle that case.
Regarding the other answers: I agree that many of the proposed "solutions" to this problem have dubious complexity claims, and if their time complexities aren't better in some way than either:
O(n)
time and space)O(n*log(n))
time, O(1)
space)...then you may as well just solve the problem by sorting.
However, we can get better complexities (and more importantly, genuinely faster solutions):