Skip to main content

1647 - Minimum Deletions to Make Character Frequencies Unique

Details

KeyValue
Linkhttps://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/
LanguagePython 3
Runtime133 ms, faster than 91.66% of Python3 online submissions for Minimum Deletions to Make Character Frequencies Unique
Memory Usage14.9 MB, less than 51.90% of Python3 online submissions for Minimum Deletions to Make Character Frequencies Unique
Datastructuresset, dict
AlgorithmsCounter & decrement until unique
ComplexityTime: O(N) Memory: O(1)

Procedure

  1. ...

Code

class Solution:
def minDeletions(self, s: str) -> int:
result, count, cache = 0, Counter(s), set()

for value in count.values():
while value in cache and value > 0:
value -= 1
result += 1

cache.add(value)

return result