Practice Minimum Deletions for At Most K Distinct Characters
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Deletions for At Most K Distinct Characters
Problem Statement
You are given a string s consisting of lowercase English letters, and an integer k. Your task is to delete some (possibly none) of the characters in the string so that the number of distinct characters in the resulting string is at most k. Return the minimum number of deletions required to achieve this.
Source: Minimum Deletions for At Most K Distinct Characters on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "abc", k = 2
1
# Example 2
s = "aabb", k = 2
0
# Example 3
s = "yyyzz", k = 1
2
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Deletions for At Most K Distinct Characters.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.