#K4806. Valid String Determination
Valid String Determination
Valid String Determination
In this problem, you are given a string and you need to determine whether it can be considered valid by checking if all characters appear the same number of times, or if it can be made valid by removing no more than one character. A string is valid if one of the following conditions holds:
- All characters in the string have the same frequency.
- If you remove exactly one occurrence of any character, then the frequency of the remaining characters becomes equal.
For example, consider the string (s = \texttt{aabbccc}). The frequencies are: (a:2,\ b:2,\ c:3). Removing one occurrence of (c) would result in (a:2,\ b:2,\ c:2), making the string valid. Therefore, the answer is YES, otherwise NO.
Your task is to process multiple test cases. For each test case, you are given a single string, and you need to output YES or NO based on the criteria above.
inputFormat
The first line of input contains an integer (T) representing the number of test cases. Each of the next (T) lines contains a single string (s). The string consists of lowercase English letters only.
outputFormat
For each test case, output a single line containing the word YES if the string can be made valid under the given criteria, or NO otherwise.## sample
3
aabbcc
aabbccc
abc
YES
YES
YES
</p>