I am trying to find the xor value of all the characters (except middle one in case of odd length) and if that equals 0, the two halves has the same frequency of each number (ord() of character in python) and has same characters. I have seen people using XOR to find out an odd number in a list as two numbers with same int value should have a XOR value of 0. When we do XOR for all characters, if there exists a pair for each character in each half, the final value should be 0.
n = int(input()) for _ in range(n): chars = list(input().lower()) ords = [ord(c) for c in chars] xor_val = ords.pop() ^ ords.pop(0) while len(ords) > 1: xor_val ^= ords.pop() ^ ords.pop(0) if not xor_val: print('YES') else: print('NO')
However, it gives Wrong Answer