easyCountingGreedyHash TableSortingString 0 views
Minimum Deletions for At Most K Distinct Characters
You are given a string s consisting of lowercase English letters, and an integer k.
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.
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.
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.