I count the frequency of each character in the string. Then I sort these frequencies to facilitate comparison. For each possible target frequency f (taken from any of the observed frequencies), I check how many deletions are needed to make all other character frequencies fall within [f, f + k].
class Solution:
def minimumDeletions(self, word: str, k: int) -> int: