I’m getting a Wrong Answer error and I’m not able to figure out the issue.
testCase = int(input())
for i in range(testCase):
string = input()
result = 0
length = len(string)
if length >= 2 and length <= 100:
if length % 2 != 0:
string = string[: length // 2] + string[length // 2 + 1 :]
for i in string:
result ^= ord(i)
if result == 0:
print("YES")
else:
print("NO")
else:
print("NO")
If you look at @ssjgz test-case, you will get an idea, its because you are using XOR because you interpreted the definition of lapindrome given in the problem wrongly. Read the problem statement correctly.
Moreover, you can solve the problem using collections module in a more pythonic way.
@mwaheed
From the comments on the post, I’ve realized that I’ve interpreted the question in the wrong way.
I thought that if each individual character is present in the string for even a number of times than the string will be Lapindrome else not, but this interpretation fails for the test case mention in the comments (bbaaaa).
In this scenario what I was doing is that I got all the ASCII values of each character and ran XOR operator on all these values. If the result is 0 then each and every individual character is present for even a number of times else not.
Read the first answer of this post to know more about XOR