12. Minimum Deletions to Make Character Frequencies Unique
Last updated
Last updated
class Solution {
public:
int minDeletions(string s) {
unordered_map<char, int> chars;
for (char c : s) {
chars[c]++;
}
unordered_set<int> freqSet;
int count = 0;
for (const auto& pair : chars) {
int freq = pair.second;
while (freq > 0 && freqSet.count(freq)) {
freq--;
count++;
}
freqSet.insert(freq);
}
return count;
}
};