#K2406. Balanced Binary String Rearrangement
Balanced Binary String Rearrangement
Balanced Binary String Rearrangement
You are given a binary string s
consisting solely of characters '0' and '1'. Your task is to determine whether the string can be rearranged to form a balanced binary string. A balanced binary string is defined as a string in which the number of '0's is equal to the number of '1's.
Input Format: The input begins with a single integer denoting the number of test cases. Following this, each test case consists of a single line containing the binary string.
Output Format: For each test case, output YES
if the string can be rearranged into a balanced binary string, otherwise output NO
.
Formally, given a binary string \( s \), let \( count_0 \) be the number of occurrences of '0' and \( count_1 \) be the number of occurrences of '1'. The string can be rearranged into a balanced binary string if and only if \( count_0 = count_1 \).
Example:
Input: 3 1100 101 110</p>Output: YES NO NO
inputFormat
The first line of input contains an integer T denoting the number of test cases. Each of the following T lines contains a single binary string.
outputFormat
For each test case, output 'YES' if the binary string can be rearranged to form a balanced binary string (i.e. the count of 0's equals the count of 1's); otherwise, output 'NO'. Each result should be on a new line.## sample
3
1100
101
110
YES
NO
NO
</p>