#K15036. Super Balanced Strings
Super Balanced Strings
Super Balanced Strings
A string is considered super balanced if it meets one of the following conditions:
- All characters occur the same number of times, i.e. \(f(c_1) = f(c_2) = \cdots = f(c_k)\) for every character \(c_i\) in the string.
- There is exactly one character that occurs one more time than every other character. In other words, if we let \(m\) be the common frequency of the other characters and \(m+1\) be the frequency of the unique character, then the string is super balanced.
For example:
- Input: aabbcc
Output: YES - Input: aabbccc
Output: YES - Input: aabbcccc
Output: NO
Your task is to determine whether each given string is super balanced.
inputFormat
The first line contains an integer (T) denoting the number of test cases. Each of the following (T) lines contains a non-empty string.
outputFormat
For each test case, output "YES" if the string is super balanced; otherwise, output "NO". Each result should be printed on a new line.## sample
5
aabbcc
aabbccc
aabbcccc
abcabcabc
aaa
YES
YES
NO
YES
YES
</p>