Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 

Chef has a number D containing only digits 0's and 1's. He wants to make the number to have all the digits same. For that, he will change exactly one digit, i.e. from 0 to 1 or from 1 to 0. If it is possible to make all digits equal (either all 0's or all 1's) by flipping exactly 1 digit then output "Yes", else print "No" (quotes for clarity)

------ Input ------ 

The first line will contain an integer T representing the number of test cases.
Each test case contain a number made of only digits 1's and 0's on newline

------ Output ------ 

Print T lines with a "Yes" or a "No", depending on whether its possible to make it all 0s or 1s or not. 

------ Constraints ------ 

Subtask #1: (40 points)

$1 ≤ T ≤ 50$
$1 ≤ Length of the number D ≤ 50$
 
Subtask #2: (60 points)

$1 ≤ T ≤ 10$
$1 ≤ Length of the number D ≤ 10^{5}$

----- Sample Input 1 ------ 
2

101

11
----- Sample Output 1 ------ 
Yes

No
----- explanation 1 ------ 
Example case 1. In 101, the 0 can be flipped to make it all 1..
Example case 2. No matter whichever digit you flip, you will not get the desired string.

Source: codechef | Difficulty: EASY
Tags: Constructive algorithms

Data structures

Ad-hoc


Solutions:
for i in range(int(input())):
	a = input()
	count0 = a.count('0')
	count1 = a.count('1')
	if count0 == 1 or count1 == 1:
		print('Yes')
	else:
		print('No')


i = int(input())
for j in range(i):
	lst = list(input())
	if lst.count('0') == 1 or lst.count('1') == 1:
		print('Yes')
	else:
		print('No')


from collections import Counter
for _ in range(int(input())):
	a = input()
	c = Counter(a)
	if c['1'] == 1 or c['0'] == 1:
		print('Yes')
	else:
		print('No')


tests = int(input())
for test in range(tests):
	my_list = input()
	twos = 0
	ones = 0
	for i in my_list:
		if i == '1':
			ones += 1
		else:
			twos += 1
	if ones == 1 or twos == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = input()
	o = n.count('1')
	z = n.count('0')
	if o == 1 or z == 1:
		print('Yes')
	else:
		print('No')


for t in range(int(input())):
	number = input()
	ones = number.count('1')
	zeros = number.count('0')
	if ones == 1 or zeros == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	s = input()
	c0 = s.count('0')
	c1 = s.count('1')
	if c0 == 1 or c1 == 1:
		print('Yes')
	else:
		print('No')


T = int(input())
for _ in range(T):
	D = input().strip()
	count_0 = D.count('0')
	count_1 = D.count('1')
	if count_0 == 1 or count_1 == 1:
		print('Yes')
	elif count_0 == 0 or count_1 == 0:
		print('No')
	else:
		print('No')


for _ in range(0, int(input())):
	b = input()
	ze = b.count('0')
	on = b.count('1')
	if ze == 1 or on == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	x = list(input())
	if x.count('0') == 1 or x.count('1') == 1:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	string = input()
	one = 0
	zero = 0
	for j in range(len(string)):
		if string[j] == '1':
			one += 1
		else:
			zero += 1
	if one == 1 or zero == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	lst = list(input())
	if lst.count('0') == 1 or lst.count('1') == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	s = input()
	p = 0
	q = 0
	for i in s:
		if i == '0':
			p = p + 1
		else:
			q = q + 1
	if p == 1 or q == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	s = input()
	n = len(s)
	ones = s.count('1')
	if ones == n - 1 or ones == 1:
		print('Yes')
	else:
		print('No')


for joe_mama in range(int(input())):
	n = input()
	c = 0
	d = 0
	for i in n:
		if i == '1':
			c += 1
		else:
			d += 1
	if c == 1 or d == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	num = str(input())
	count1 = num.count('0')
	count2 = num.count('1')
	if count1 == 1 or count2 == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	number = str(input())
	if number.count('0') == 1 or number.count('1') == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	s = str(input())
	s0 = s.count('0')
	s1 = s.count('1')
	if s0 == 1 or s1 == 1:
		print('Yes')
	else:
		print('No')


n = int(input())
for i in range(n):
	l = list(input())
	if l.count('0') == 1 or l.count('1') == 1:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	l = list(map(int, input()))
	x = l.count(1)
	y = l.count(0)
	if x == 1 or y == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	a = input()
	c0 = 0
	c1 = 0
	for i in a:
		if i == '0':
			c0 += 1
		elif i == '1':
			c1 += 1
	if c0 == 1 or c1 == 1:
		print('Yes')
	else:
		print('No')
	t -= 1


for _ in range(int(input())):
	d = input()
	if d.count('0') == 1 or d.count('1') == 1:
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	count_0 = 0
	D = input()
	if D.count('0') == 1:
		print('Yes')
	elif D.count('1') == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	d = input()
	one = 0
	zero = 0
	for i in d:
		if i == '1':
			one += 1
		else:
			zero += 1
	if one == 1 or zero == 1:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	s = input()
	if s.count('0') == 1 or s.count('1') == 1:
		print('Yes')
	else:
		print('No')


cases = int(input())
for _ in range(cases):
	s = input()
	zeros = s.count('0')
	ones = s.count('1')
	if zeros == 1 or ones == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	s = input()
	if s.count('1') == len(s) - 1:
		print('Yes')
	elif s.count('0') == len(s) - 1:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0 and t <= 50:
	l = input()
	x = 0
	y = 0
	ls = str(l)
	for i in range(len(ls)):
		if ls[i] == '0':
			x += 1
		else:
			y += 1
	if x == 1 or y == 1:
		print('Yes')
	else:
		print('No')
	t -= 1


t = int(input())
for i in range(t):
	num = input()
	zeros = num.count('0')
	ones = num.count('1')
	if zeros == 1 or ones == 1:
		print('Yes')
	elif zeros == 0 or ones == 0:
		print('No')
	else:
		print('No')


t = int(input())
for i in range(t):
	bin_str = input()
	arr = list(bin_str)
	if len(arr) == 1:
		print('Yes')
	else:
		set_arr = list(set(arr))
		if len(set_arr) == 1:
			print('No')
		else:
			zero_count = arr.count('0')
			one_count = arr.count('1')
			min_val = min(zero_count, one_count)
			if min_val > 1:
				print('No')
			else:
				print('Yes')


t = int(input())
for _ in range(t):
	s = input()
	ones = 0
	zeros = 0
	for i in s:
		if i == '1':
			ones += 1
		else:
			zeros += 1
	if ones == 1 or zeros == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	kannaaa = str(input())
	count11 = kannaaa.count('0')
	count22 = kannaaa.count('1')
	if count11 == 1 or count22 == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	l = list(input())
	one = l.count('1')
	zero = l.count('0')
	if one == 1 or zero == 1:
		print('Yes')
	else:
		print('No')
	t -= 1


t = int(input())
while t > 0:
	a = list(input())
	if a.count('0') == 1 or a.count('1') == 1:
		print('Yes')
	else:
		print('No')
	t -= 1


t = int(input())
for i in range(t):
	n = input()
	if n.count('1') == 1 or n.count('0') == 1:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	a = input()
	if list(a).count('0') == 1 or list(a).count('1') == 1:
		print('Yes')
	else:
		print('No')


from collections import Counter

def test():
	lst = list(input())
	if lst.count('0') == 1 or lst.count('1') == 1:
		print('Yes')
	else:
		print('No')
t = int(input())
for _ in range(t):
	test()


T = int(input())
for i in range(T):
	D = input()
	count1 = D.count('0')
	count2 = D.count('1')
	if count1 == 1 or count2 == 1:
		print('Yes')
	else:
		print('No')


b = int(input())
for i in range(b):
	a = list(input())
	l = 0
	k = 0
	for i in a:
		if i == '1':
			l = l + 1
		elif i == '0':
			k = k + 1
	if k + l == len(a) and l - k == len(a) - 2:
		print('Yes')
	elif k + l == len(a) and k - l == len(a) - 2:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	n = input().strip()
	(z, o) = (0, 0)
	l = len(n)
	for j in n:
		if j == '0':
			z += 1
		else:
			o += 1
	if z == 1 or o == 1:
		print('Yes')
	else:
		print('No')