Suppose an array contains n elements. The elements is in the range 109. We want to know, for every element in the array, the position of the leftmost element that is smaller than that one.
An example:
The array: 20 3 10 5 1 9 100
Answer: 0 0 2 2 0 2 1
Can this problem be done in O(n)?