I am stuck on this problem:Given an array $A$ of the first $n$ natural numbers randomly permuted, an array $B$ is   constructed, such that  $B(k)$ is the number of elements from $A(1)$ to $A(k-1)$ which are smaller than $A(k)$.  i) Given $A$ can you find $B$ in $O(n)$ time?  ii) Given $B$ can you find $A$ in $O(n)$ time?Here, $B(1) = 0$. For a concrete example:$$\begin{vmatrix}  A & 8 & 4 & 3 & 1 & 7 & 2 & 9 & 6 & 5 \\  B & 0 & 0 & 0 & 0 & 3 & 1 & 6 & 4 & 4 \\\end{vmatrix}$$Can anyone help me? Thanks.
Finding number of smaller elements for each element in an array efficiently
algorithms;arrays;permutations