I understand that this question can be solved most efficiently by utilizing selection and partition, both of which can be completed in linear time. My idea was to select the nth smallest element in the array O(n), which in the example given would be 34, so j = 3 in this case. Then from i = 1 to j - 1, if the sequence is decreasing, set B[i] = j, the moment the sequence increases, set B[i] = i + 1 and stop. Recursively call the procedure on the array A[j ... n]. I don't think this is efficient at all and not sure if it is even correct or what the final complexity of my algorithm is.
Summary
(1) select nth smallest (index j) using deterministic select algorithm o(n)
(2)
function:
for i = 1 to n do
for j = i + 1 to n do
if A[j] > A[i] then B[i] = j , B[j] = n + 1
for k = i + 1 to j - 1 do
if A[k] < A[k + 1]
B[k] = j
else
B[k] = k + 1
recursive function(A[j + 1, ... n]) // recursively perform procedure on portion of array starting from j + 1 (after max) to n.
