Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Became Hot Network Question
2 edited title

1

# Fast way to find number of list elements less than a given integer

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}.