I saw the following question:
Given an array A of integers, find an integer k that is not present in A. Assume that the integers are 32-bit signed integers.
How to solve it?
Thank you
//// update -- This is the provided solution - but I don't think it is correct //// Consider a very simple hash function F(x)=x mod (n+1). we can build a bit-vector of length n+1 that is initialized to 0 and for every element in A, we set bit F(A[i]) to 1.Since there are only n elements in the array, we can find the missing element easily.
I think the above solution is wrong.
For example, A [ 2, 100, 4 ], then both 4 and 100 will match to the same place.