Skip to content

Practice Minimum Deletions to Make String K-Special

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3085
LeetCode Problem

Minimum Deletions to Make String K-Special

Problem Statement

You are given a string word and an integer k. We consider word to be k-special if |freq(word[i]) - freq(word[j])| <= k for all indices i and j in the string. Here, freq(x) denotes the frequency of the character x in word, and |y| denotes the absolute value of y. Return the minimum number of characters you need to delete to make word k-special.

Source: Minimum Deletions to Make String K-Special on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word = "aabcaba", k = 0
Output
3

# Example 2

Input
word = "dabdcbdcdcd", k = 2
Output
2

# Example 3

Input
word = "aaabaaa", k = 2
Output
1

Constraints

1 <= word.length <= 10^5
0 <= k <= 10^5
word consists only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Minimum Deletions to Make String K-Special.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.