#C7951. Balanced String Checker
Balanced String Checker
Balanced String Checker
Given a string s, determine whether it is balanced. A string is considered balanced if every distinct character in the string appears the same number of times. For example, the string "aabb"
is balanced because both 'a' and 'b' appear twice, while "aabbbc"
is not balanced.
Your program should read an integer T denoting the number of test cases. For each test case, a string is provided. For each string, print YES
if it is balanced, otherwise print NO
.
The condition for a string to be balanced can be expressed as: $$\forall c_1, c_2 \in S, \; f(c_1)=f(c_2)$$ where \(f(c)\) denotes the frequency of character \(c\) in the string.
inputFormat
The input consists of multiple lines. The first line contains a single integer T
(1 ≤ T ≤ 105), representing the number of test cases. Each of the following T
lines contains a single string s
consisting of lowercase letters.
Note: The string can be empty, in which case it is considered balanced.
outputFormat
For each test case, output a single line with either YES
if the input string is balanced, or NO
otherwise.
3
aabb
abcabc
aabbbc
YES
YES
NO
</p>