Monday, 16 July 2012

Array of natural number

Consider an array 'A' of 1st n natural numbers randomly permuted. Consider an array B formed from array A as given below
B(k) = number of elements from A(1) to A(k-1) which are smaller than A(k)
Obviously B(1) = 0;
i) Given A can you find B in O(n)
ii) Given B can you find A in O(n)

Disclaimer: The question was asked to me during GSachs interview and of course I was unable to answer. I am still unable to figure out the solution