You are given two arrays A[] and B[], each of size N, where each element A_{i} and B_{j }are distinct. Let's consider an integer X is the count of all different pairs of A_{i} and B_{j}, such that A_{i} XOR B_{j} is present in any of the two arrays. Return "Yes" (case-sensitive) if X is even, else return "No".
 
Example 1:
Input:
N =  3
A[] = {1, 5, 7}
B[] = {2, 4, 8}
Output:
Yes
Explanation:
XOR(1,2)=3
XOR(1,4) = 5 is present in A[]
XOR(1,8) = 9
XOR(5,2) = 7 is present in A[]
XOR(5,4) = 1 is present in A[]
XOR(5,8) = 13
XOR(7,2) = 5 is present in A[]
XOR(7,4) = 3
XOR(7,8)=15
Out of all these XOR operations, 
5,7,1,5 are present, so count of X = 4 
which is even. Hence the output is "Yes".
Example 2:
Input:
N =  2
A[] = {1, 5}
B[] = {2, 4}
Output:
Yes
Explanation:
XOR(1,2) = 3
XOR(1,4) = 5 is present in A[]
XOR(5,2)=7
XOR(5,4)=1 is present in A[]
Out of all these XOR operations,
1,5 are present,
So count of X = 2 which is even.
Hence the output is "Yes".
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function yesXorNo() which takes an Integer N and two arrays A[] and B[] of size N as input and returns "Yes" if the count of X is even, else "No".
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{5}
1 <= A[i],B[i] <= 10^{9}

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Number theory

Mathematics

Starter code: #User function Template for python3

class Solution:
    def yesXorNo(self, N, A, B):
        # code here

Solutions:
class Solution:

	def yesXorNo(self, N, A, B):
		return 'Yes'


class Solution:

	def yesXorNo(self, N, A, B):
		xorr = 0
		obj = []
		for (i, j) in zip(A, B):
			obj.append(i ^ j)
			obj.append(j ^ i)
		map = {}
		for i in A:
			map[str(i)] = 0
		for i in B:
			map[str(i)] = 0
		for i in obj:
			if map.__contains__(str(i)):
				xorr += 1
		if xorr % 2 == 0:
			return 'Yes'
		return 'No'


class Solution:

	def yesXorNo(self, n, a, b):
		return 'Yes'


class Solution:

	def yesXorNo(self, N, A, B):
		return 'Yes'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ob = Solution()
		print(ob.yesXorNo(N, A, B))


class Solution:

	def yesXorNo(self, N, A, B):
		l = []
		l2 = []
		for i in A:
			for j in B:
				l.append([i, j])
			for p in l:
				if p[0] ^ p[1] in (A or B):
					l2.append('yes')
				if len(l2) % 2 == 0:
					return 'Yes'
				else:
					return 'No'


class Solution:

	def yesXorNo(self, N, A, B):
		tmpa = sum(A)
		tmpb = sum(B)
		if tmpa ^ tmpb % 2 != 0:
			return 'Yes'
		else:
			return 'No'


from collections import defaultdict

class Solution:

	def yesXorNo(self, n, A, B):
		return 'Yes'


class Solution:

	def yesXorNo(self, N, A, B):
		s = 'Yes'
		s1 = 'No'
		for i in range(N):
			if A[i] ^ B[i] in A or B:
				return s
		return s1


class Solution:

	def yesXorNo(self, N, A, B):
		return 'Yes'
		result = {}
		for i in A:
			result[i] = True
		for i in B:
			result[i] = True
		for i in A:
			for j in B:
				if result.get(i ^ j, False):
					return 'Yes'
		return 'No'