Counts the occurrences of each distinct element and places them in the output array in order.
Explain code with DocComment! Try out your own code!