A general doubt,not related to this problem

how can we print number of greater elements on left for every index in an efficient way better than O(n^2)?

@chhabrapiyush480 hi you can use self balancing bst for this problem.Set data structure in stl uses self balancing bst ,so you can use that ,here are steps ,you have to use inbuilt set functions in stl:
Traverse the array element from i=len-1 to 0 and insert every element in a set.
Find the first element that is greater than A[i] using upper_bound function.
Find the distance between above found element and the beginning of the set using distance function.
Store the distance in another array Lets say CountSmaller.
Print that array .

that’s nice,thanks,(in addition we should use multi_set instead of set,considering same non-distinct elements in array).

@chhabrapiyush480 yeah that you can also use.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.