#K7531. Rearrange String for K Distinct Characters

    ID: 34391 Type: Default 1000ms 256MiB

Rearrange String for K Distinct Characters

Rearrange String for K Distinct Characters

Given a string \(s\) and an integer \(k\), determine whether it is possible to rearrange the characters of \(s\) such that there are exactly \(k\) distinct characters in the string. Note that rearranging the string does not change the frequency of each character. Therefore, if \(d\) is the number of distinct characters in \(s\), then the answer is "YES" if \(d \ge k\) and "NO" otherwise.

inputFormat

The first line of input contains an integer (T) representing the number of test cases. Each of the following (T) lines contains a string (s) and an integer (k) separated by a space.

outputFormat

For each test case, output a single line with either "YES" or "NO" indicating whether it is possible to rearrange the string to have exactly (k) distinct characters.## sample

3
abc 2
aaa 1
abcd 5
YES

YES NO

</p>