I'm trying to make a function whose input is a list, and that outputs a list for which the nth element is the number of elements in the input less than n. So far, I have
l2 = Table[Length[Select[l1, # < n &]], {n, 1, M}]
Where l2 is the output list, l1 is the input list, and M is the desired length of l2. This gives the correct output, but is there a faster way to do this, as this function can get rather slow for larger lists.
An example of the function:
{2,2,3,3,7} —$>$ {0,0,2,4,4}.