Given N bits to an XOR - Gate find the output that will be produced. 
XOR - Gate Table:
1 ^ 1 = 0
1 ^ 0 = 1
0 ^ 1 = 1
0 ^ 0 = 0
 
Example 1:
Input:
N = 4
arr: 1 1 1 0
Output:
1
Explanation:
1 ^ 1 = 0
0 ^ 1 = 1
1 ^ 0 = 1
hence output is 1
Example 2:
Input:
N = 4
arr: 0 0 1 0
Output:
1
Explanation:
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
hence output is 1
Your Task:
You don't need to read input or print anything. Your task is to complete the function xorGate() which takes the array arr[], its size N as input parameters and returns the output after processing OR operations on N bits.
 
Expected Time Complexity: O(N)
Expected Space Complexity: O(1)
 
Constraints:
1<=N<=1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Starter code: #User function Template for python3





class Solution:

    def xorGate (self, arr, N):

        #code here

Solutions:
class Solution:

	def xorGate(self, arr, N):
		c = 0
		n = len(arr) - 1
		while n != -1:
			if arr[n] & 1 == 1:
				c += 1
			n -= 1
		if c % 2 == 0:
			return 0
		else:
			return 1


class Solution:

	def xorGate(self, arr, N):
		c = 0
		for i in range(len(arr)):
			c = c ^ arr[i]
		return c


class Solution:

	def xorGate(self, l, N):
		if len(l) == 1:
			return l[0]
		x = l[0] ^ l[1]
		for i in range(2, len(l)):
			x = x ^ l[i]
		return x


class Solution:

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


class Solution:

	def xorGate(self, arr, N):
		xor = 0
		for i in arr:
			xor ^= i
		return xor


class Solution:

	def xorGate(self, arr, N):
		if N <= 1:
			return 0
		k = arr[0] ^ arr[1]
		for i in range(2, len(arr)):
			k = k ^ arr[i]
		return k


class Solution:

	def xorGate(self, arr, N):
		item = arr[0]
		for char in arr[1:]:
			item = item ^ char
		return item


class Solution:

	def xorGate(self, arr, N):
		a = 0
		for i in range(0, N):
			a ^= arr[i]
		return a


class Solution:

	def xorGate(self, arr, N):
		s = arr.count(1)
		if s & 1:
			return 1
		return 0


class Solution:

	def xorGate(self, arr, N):
		ans = arr[0]
		for i in arr[1:]:
			if i == ans:
				ans = 0
			else:
				ans = 1
		return ans


class Solution:

	def xorGate(self, arr, N):
		if arr.count(1) % 2 == 0:
			return 0
		else:
			return 1


class Solution:

	def xorGate(self, arr, N):
		ans = 0
		for ele in arr:
			ans ^= ele
		return ans


def solve(arr, n):
	xor = arr[0]
	for i in range(1, n):
		xor = xor ^ arr[i]
	return xor

class Solution:

	def xorGate(self, arr, N):
		ans = solve(arr, N)
		return ans


class Solution:

	def xorGate(self, arr, N):
		j = 1
		s = arr[0]
		while j < N:
			s = s ^ arr[j]
			j += 1
		return s


class Solution:

	def xorGate(self, arr, N):
		final = 0
		for i in arr:
			if i == 1:
				final = final + 1
		return final % 2


class Solution:

	def xorGate(self, arr, N):
		if len(arr) == 1:
			return arr[0]
		s = arr[0] ^ arr[1]
		if len(arr) < 3:
			return s
		for x in range(2, N):
			s ^= arr[x]
		return s


class Solution:

	def xorGate(self, arr, N):
		x = arr[0]
		for i in range(1, N):
			x = x ^ arr[i]
		return x
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = [int(i) for i in input().split()]
		ob = Solution()
		print(ob.xorGate(arr, N))


class Solution:

	def xorGate(self, arr, N):
		sum_ = 0
		for i in range(N):
			sum_ += arr[i]
		if sum_ % 2 == 0:
			return 0
		return 1


class Solution:

	def xorGate(self, arr, N):
		c = 0
		for i in arr:
			if i == 1:
				c += 1
		if c % 2 == 0:
			return 0
		else:
			return 1