Skip to content

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.

Easy#3545
LeetCode Problem

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

Input
s = "abc", k = 2
Output
1

# Example 2

Input
s = "aabb", k = 2
Output
0

# Example 3

Input
s = "yyyzz", k = 1
Output
2

Constraints

1 <= s.length <= 16
1 <= k <= 16
s consists only of lowercase English letters.

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.