Leetcode 1741 Solution

This article provides solution to leetcode question 1741 (sort-array-by-increasing-frequency)

https://leetcode.com/problems/sort-array-by-increasing-frequency

Solution

class Solution:
    def frequencySort(self, nums: List[int]) -> List[int]:
        m = collections.defaultdict(int)
        for num in nums:
            m[num] += 1

        a = []
        for num in nums:
            a.append((m[num], -num))
        a.sort()

        return [-num for _, num in a]