Find XOR from 1 to n...takes O(n) ans = X1 Now fetch individual bits from array elements...again take xor...takes O(n) ans= X2
result is X1 xor X2 On Wed, Mar 2, 2011 at 1:44 AM, bittu <[email protected]> wrote: > An array A[1...n] contains all the integers from 0 to n except for one > number which is missing. In this problem, we cannot access an entire > integer in A with a single operation. > The elements of A are represented in binary, and the only operation we > can use to access them is “fetch the jth bit of A[i]”, which takes > constant time. Write code to find the missing integer. Can you do it > in O(n) time? > > > > Thanks & Regards > Shashank Mani > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
