Given an array A[] of size N. The value of an array is denoted by the bit-wise XOR of all elements it contains. Find the bit-wise XOR of the values of all subarrays of A[]. 
Example 1:
Input: N = 3, A[] = {1,2,3} 
Output: 2
Explanation:
xor[1] = 1, 
xor[1, 2] = 3
xor[2, 3] = 1
xor[1, 2, 3] = 0
xor[2] = 2
xor[3] = 3
Result : 1 ^ 3 ^ 1 ^ 0 ^ 2 ^ 3 = 2
Example 2:
Input: N = 2, A[] = {1,2} 
Output: 0
Explanation:
xor[1] = 1, 
xor[1, 2] = 3
xor[2] = 2
Result : 1 ^ 3 ^ 2 = 0
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function gameOfXor() which takes an integer N and array A[] as input parameters and returns the answer.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{5}
1 <= A[i ]<= 10^{5}

Difficulty: EASY
Tags: Bit manipulation

Data structures

Mathematics
Skill types: Bit manipulation

Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

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

Solutions:
class Solution:

	def gameOfXor(self, N, A):
		if N % 2 == 0:
			return 0
		r = 0
		for i in range(0, N, 2):
			r = r ^ A[i]
		return r


class Solution:

	def gameOfXor(self, N, A):
		ans = 0
		for i in range(len(A)):
			count = (i + 1) * (len(A) - i)
			if count % 2 != 0:
				ans = ans ^ A[i]
		return ans


class Solution:

	def gameOfXor(self, N, A):
		k = 0
		d = dict()
		for i in range(N):
			if A[i] not in d:
				d[A[i]] = (i + 1) * (N - i)
			else:
				d[A[i]] = d[A[i]] + (i + 1) * (N - i)
		for i in d:
			if d[i] % 2 != 0:
				k = k ^ i
		return k


class Solution:

	def gameOfXor(self, N, A):
		res = 0
		for i in range(N):
			freq = (i + 1) * (N - i)
			if freq & 1:
				res ^= A[i]
		return res


class Solution:

	def gameOfXor(self, N, A):
		if N % 2 == 0:
			return 0
		else:
			ans = 0
			for i in range(0, N):
				if i % 2 == 0:
					ans ^= A[i]
			return ans


class Solution:

	def gameOfXor(self, N, arr):
		if N & 1 == 0:
			return 0
		ans = 0
		for i in range(N):
			if i & 1 == 0:
				ans ^= arr[i]
		return ans


class Solution:

	def gameOfXor(self, n, A):
		if n % 2 == 0:
			return 0
		ans = 0
		for i in range(n):
			if i + 1 & 1:
				ans ^= A[i]
		return ans


class Solution:

	def gameOfXor(self, N, A):
		Xor = 0
		if N % 2 == 0:
			return 0
		for i in range(0, len(A), 2):
			Xor ^= A[i]
		return Xor


class Solution:

	def gameOfXor(self, N, A):
		vk = 0
		if N & 1:
			for i in range(0, N, 2):
				vk ^= A[i]
		return vk


class Solution:

	def gameOfXor(self, n, A):
		a = 0
		if n % 2 != 0:
			for i in range(N):
				if i % 2 == 0:
					a = a ^ A[i]
			return a
		else:
			return 0


class Solution:

	def gameOfXor(self, N, A):
		if N & 1 == 0:
			return 0
		else:
			a = 0
			for i in range(0, N):
				if i + 1 & 1:
					a ^= A[i]
			return a


class Solution:

	def gameOfXor(self, N, A):
		t = 0
		if N % 2 == 0:
			return 0
		else:
			for i in range(N):
				if i & 1 == 0:
					t = t ^ A[i]
		return t


class Solution:

	def gameOfXor(self, N, A):
		res = 0
		for i in range(0, N):
			f = (i + 1) * (N - i)
			if f % 2 == 1:
				res = res ^ A[i]
		return res


class Solution:

	def gameOfXor(self, n, arr):
		ans = 0
		if n % 2 == 0:
			return 0
		else:
			for i in range(0, n, 2):
				ans ^= arr[i]
			return ans


class Solution:

	def gameOfXor(self, n, arr):
		(l, r) = (1, n)
		x = 0
		for i in range(n):
			x ^= arr[i] * (l * r % 2)
			l += 1
			r -= 1
		return x


class Solution:

	def gameOfXor(self, N, A):
		xor = 0
		for i in range(N):
			times = (N - i) * (i + 1)
			xor ^= times % 2 * A[i]
		return xor


class Solution:

	def gameOfXor(self, n, a):
		res = 0
		for i in range(n):
			if (n - i) * (i + 1) & 1:
				res ^= a[i]
		return res


class Solution:

	def gameOfXor(self, N, A):
		if N % 2 == 0:
			return 0
		xor = 0
		for i in range(0, N, 2):
			xor ^= A[i]
		return xor
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = list(map(int, input().split()))
		ob = Solution()
		print(ob.gameOfXor(N, A))


class Solution:

	def gameOfXor(self, n, l):
		if n == 1:
			return l[0]
		elif n % 2 == 0:
			return 0
		else:
			ans = 0
			for i in range(0, n, 2):
				ans = ans ^ l[i]
			return ans


class Solution:

	def gameOfXor(self, N, A):
		res = 0
		for (index, val) in enumerate(A):
			freq = (index + 1) * (N - index)
			res ^= A[index] if freq % 2 else 0
		return res


class Solution:

	def gameOfXor(self, N, A):
		n = N
		if n & 1 == 0:
			return 0
		k = 1
		arr = A
		for i in range(n):
			if k & 1 == 0:
				arr[i] = 0
			k += 1
		ans = 0
		for i in arr:
			ans = ans ^ i
		return ans


class Solution:

	def gameOfXor(self, n, a):
		if n % 2 == 0:
			return 0
		xor = 0
		i = 0
		while i < n:
			xor = xor ^ a[i]
			i += 2
		return xor


class Solution:

	def gameOfXor(self, N, A):
		xor = 0
		prev_num = 0
		for i in range(N):
			curr_num = N - i + prev_num - i
			if curr_num % 2 != 0:
				xor = xor ^ A[i]
			prev_num = curr_num
		return xor


class Solution:

	def gameOfXor(self, N, A):
		xor = 0
		for i in range(len(A)):
			freq = (i + 1) * (N - i)
			if freq % 2 == 1:
				xor = xor ^ A[i]
		return xor


class Solution:

	def gameOfXor(self, n, A):
		if n % 2 == 0:
			return 0
		res = 0
		for i in range(0, n, 2):
			res = res ^ A[i]
		return res


class Solution:

	def gameOfXor(self, N, A):
		r = 0
		for n in range(N):
			t = (n + 1) * (N - n)
			if t % 2:
				r = r ^ A[n]
		return r


class Solution:

	def gameOfXor(self, N, A):
		res = 0
		for i in range(N):
			left = i + 1
			right = N - i
			occur = left * right
			if occur & 1:
				res ^= A[i]
		return res