2
$\begingroup$

I am stuck in this problem. Can anyone help me. Thanks.

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)

0 Answers 0