https://leetcode.com/problems/sort-characters-by-frequency/class Solution: def frequencySort(self, s: str) -> str: count = Counter(s) # char -> cnt buckets = defaultdict(list) # frequency -> [char] for char, cnt in count.items(): buckets[cnt].append(char) res = [] for i in range(len(s), 0, -1): for c in buckets[i]: ..