At Moloco, managing and analyzing big data is an important part of the core business. A colleague raised a complicated question one day, and you have to help resolve it.
You are given an array A of n distinct integers. Build a new array S of n integers, where S[i] is the number of elements placed before A[i] that are smaller than A[i].
S[i]=∣{j:1≤j<i, A[j]<A[i]}∣
Indices start at 1. For instance, if A=[10,5,12,1,11], then S=[0,0,2,0,3].