#K48197. Minimum Changes to Achieve K Distinct Characters
Minimum Changes to Achieve K Distinct Characters
Minimum Changes to Achieve K Distinct Characters
Given a string s
and an integer k
, determine the minimum number of character modifications required so that the string contains at least k
distinct characters. In other words, if \( \lvert U \rvert \) denotes the number of unique characters in s
, then the answer is given by
[ \max(0, k - \lvert U \rvert ) ]
You may assume that k
is less than or equal to the length of s
.
inputFormat
The input consists of two lines:
- The first line contains a single integer
k
. - The second line contains the string
s
.
outputFormat
Output a single integer representing the minimum number of changes required so that s
contains at least k
distinct characters.
5
aaabbcc
2
</p>