#K16286. Minimum Deletions to Limit Letter Frequency
Minimum Deletions to Limit Letter Frequency
Minimum Deletions to Limit Letter Frequency
You are given a string s
consisting of lowercase letters. Your task is to determine the minimum number of deletions required so that every letter appears at most twice in the string.
If a letter appears more than twice, you must remove enough occurrences of that letter so that its total count is reduced to 2.
For example, if s
is "aaabbbc", then deleting one 'a' and one 'b' will result in "aabbc", where each letter appears at most twice, so the answer is 2.
Input Constraints: The string length is at least 0 and at most 105 characters.
Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout).
inputFormat
The input consists of a single line containing the string s
.
Example:
aaabbbc
outputFormat
Output a single integer representing the minimum number of deletions required to ensure that every letter in the string appears at most twice.
Example:
2## sample
aaabbbc
2