1647. Minimum Deletions to Make Character Frequencies Unique
https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/
Python
from collections import Counter
class Solution:
def minDeletions(self, s: str) -> int:
counts = sorted(Counter(s).values(), reverse=True)
ans = 0
max_allowed = len(s)
for count in counts:
if count > max_allowed:
ans += count - max_allowed
max_allowed = max(0, max_allowed-1)
else:
max_allowed = max(0, count-1)
return ans