• Sort Array by Element Frequency

Question related to mission Sort Array by Element Frequency

 

The problem description says, "Sort the given iterable so that its elements end up in the decreasing frequency order, that is, the number of times they appear in elements. If two elements have the same frequency, they should end up in the same order as the first appearance in the iterable."

My understanding of the last statement in the problem description tells me that stable sort must be used. If my understanding is correct, the output for frequency_sort[4, 6, 2, 2, 6, 4, 4, 4] should not be [4, 4, 4, 4, 6, 6, 2, 2] as stated in the problem example. Since 6 and 2 have the same frequency, shouldn't they appear in the sorted list as in the order in which they appear in the input list i.e. the first 6 precedes both 2s and the second 6 follows after the 2s? It should be [4, 4, 4, 4, 6, 2, 2, 6], no?