Reputation: 71
You are given a string. Your task is to determine whether number of occurrences of some character in the string is equal to the sum of the numbers of occurrences of other characters in the string.
Input
The first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contains one string S consisting of lowercase latin letters.
Output
For each test case, output a single line containing "YES" if the string satisfies the condition given above or "NO" otherwise.
Example
Input:
4 acab zzqzqq abc kklkwwww
Output:
YES YES NO YES
My code:
testcases = int(input())
for i in range(testcases):
string = list(input())
x = len(string)
y = max(string,key=string.count)
z = string.count(y)
if z==1:
print('NO')
elif x/z==2:
print('YES')
else:
print('NO')
Codechef gives me Wrong Answer after I've submitted this code. Can anyone tell me why?
Upvotes: 0
Views: 621
Reputation: 463
Your code is not giving the right result because of your first if
statement.
According to your code:
if z==1:
print('NO')
Which means for a test case like ab
your code will give the output NO
when it should give the output yes
. Remove this if
condition and you will be good to go.
Upvotes: 2