Simple Python solution with explanation
We are going to use a dictionary to keep track of the frequeny that a number appears in the array. After we have done that we first sort the array in decreasing
We are going to use a dictionary to keep track of the frequeny that a number appears in the array. After we have done that we first sort the array in decreasing order and then sort it in increasing order by frequency. This works because sorts are guarenteed to be stable. Read this if you need help understanding why this works. https://docs.python.org/3/howto/sorting.html#sort-stability-and-complex-sorts \n```\nclass Solution:\n    def frequencySort(self, nums: List[int]) -> List[int]:\n        d = {}\n        for num in nums:\n            if num not in d:\n                d[num] = 1\n            else:\n                d[num] += 1\n        return sorted(sorted(nums, reverse=True), key=lambda x: d[x])\n```
['Python']