#C2112. Maximum Distinct Characters after Replacements
Maximum Distinct Characters after Replacements
Maximum Distinct Characters after Replacements
Given a string s
and an integer k
representing the maximum number of replacement operations allowed, determine the maximum number of distinct characters that can be obtained. In each replacement operation, you can change any character to another character that is not already in the string. Note that since there are only 26 lowercase English letters, the answer cannot exceed 26.
You should compute the answer using the formula:
$$ \text{result} = \min(26, |\text{distinct}(s)| + k) $$
where \(|\text{distinct}(s)|\) is the number of distinct characters in the string s
.
inputFormat
The input consists of two lines:
- The first line contains an integer
k
which is the maximum number of replacement operations allowed. - The second line contains the string
s
.
outputFormat
Output a single integer, which is the maximum number of distinct characters possible after at most k
replacement operations.
2
abcabc
5