LeetCode solutions

3360. Minimum Deletions to Make String K-Special

My accepted Python solution to LeetCode problem 3360, Minimum Deletions to Make String K-Special, running in 56ms.

  • Difficulty: Medium
  • Python
  • Runtime 56ms
  • Memory 17.9MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 56ms, memory 17.9MB, accepted 2026-01-02.

python
class Solution:
    def minimumDeletions(self, word: str, k: int) -> int:
        from collections import Counter
        freq = Counter(word)
        counts = sorted(freq.values())
        n = len(counts)
        result = float('inf')
        for i in range(n):
            min_freq = counts[i]
            deletions = 0
            for j in range(i):
                deletions += counts[j]
            for j in range(i, n):
                if counts[j] > min_freq + k:
                    deletions += counts[j] - (min_freq + k)
            result = min(result, deletions)
        return result

Source