#3545
Minimum Deletions for At Most K Distinct Characters
easy · 72.9% accepted · 90 likes · top 83%
hash table · string · greedy · sorting · counting
Description
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.
Solution