How to arrange an array in decreasing order of frequency of each number?

Posted by Rajendra on Stack Overflow See other posts from Stack Overflow or by Rajendra
Published on 2010-03-25T16:07:50Z Indexed on 2010/03/25 21:23 UTC
Read the original article Hit count: 300

Input : {5, 13, 6, 5, 13, 7, 8, 6, 5}

Output : {5, 5, 5, 13, 13, 6, 6, 7, 8}

The question is to arrange the numbers in the array in decreasing order of their frequency, preserving the order of their occurrence.

If there is a tie, like in this example between 13 and 6, then the number occurring first in the input array would come first in the output array.

© Stack Overflow or respective owner

Related posts about array

Related posts about interview-questions