Leetcode 1741 Solution
This article provides solution to leetcode question 1741 (sort-array-by-increasing-frequency)
Access this page by simply typing in "lcs 1741" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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]