Given an array arr[] of N integers, the task is to find the number of pairs in the array whose XOR is odd.
Example 1:
Input: N = 3, arr[] = {1, 2, 3}
Output: 2
Explanation: All pairs of array
             1 ^ 2 = 3
             1 ^ 3 = 2
             2 ^ 3 = 1
Example 2:
Input: N = 2, arr[] =  {1, 2}
Output: 1
Explanation: 1^2 =3 which is odd.
Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function countXorPair() that takes array arr and integer N as parameters and returns the desired output.
 
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
 
Constraints:
1 ≤ N ≤ 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: #User function Template for python3





class Solution:

    def countXorPair(self,arr, N):

        # Your code goes here

        

Solutions:
class Solution:

	def countXorPair(self, arr, N):
		(a, b) = (0, 0)
		for i in range(N):
			if arr[i] % 2 == 0:
				a += 1
			else:
				b += 1
		return a * b


class Solution:

	def countXorPair(self, arr, N):
		odd = 0
		even = 0
		for i in range(n):
			if arr[i] % 2 == 0:
				even += 1
			else:
				odd += 1
		return odd * even


class Solution:

	def countXorPair(self, arr, N):
		even_count = 0
		odd_count = 0
		for i in range(N):
			if arr[i] % 2 == 0:
				even_count += 1
			else:
				odd_count += 1
		return even_count * odd_count


class Solution:

	def countXorPair(self, arr, N):
		odd = 0
		for item in arr:
			odd += item % 2
		even = N - odd
		return odd * even


class Solution:

	def countXorPair(self, arr, N):
		output = []
		for number in arr:
			if number % 2 != 0:
				output.append(number)
		return len(output) * (N - len(output))


class Solution:

	def countXorPair(self, arr, N):
		odd_num = 0
		even_num = 0
		for elem in arr:
			if elem % 2 == 0:
				even_num += 1
			else:
				odd_num += 1
		return odd_num * even_num


class Solution:

	def countXorPair(self, arr, N):
		e = 0
		for i in arr:
			if i % 2 == 0:
				e += 1
		return e * (n - e)


class Solution:

	def countXorPair(self, arr, N):
		e = o = 0
		for i in arr:
			if i % 2 == 0:
				e += 1
			else:
				o += 1
		return e * o


class Solution:

	def countXorPair(self, arr, N):
		arr.sort()
		cou = 0
		num = n
		for i in range(N):
			if arr[i] % 2 != 0:
				cou += 1
				num -= 1
		return cou * num


class Solution:

	def countXorPair(self, arr, N):
		even = 0
		odd = 0
		for item in arr:
			if item % 2 == 0:
				even += 1
			else:
				odd += 1
		return even * odd


class Solution:

	def countXorPair(self, arr, N):
		k = 0
		for i in range(N):
			if arr[i] % 2 == 0:
				k = k + 1
		l = N - k
		return k * l


class Solution:

	def countXorPair(self, arr, N):
		l = len([i for i in arr if i % 2 != 0])
		return l * (n - l)


class Solution:

	def countXorPair(self, arr, N):
		oddn = 0
		for i in range(N):
			if arr[i] % 2 == 1:
				oddn += 1
		return oddn * (N - oddn)


class Solution:

	def countXorPair(self, arr, N):
		c = 0
		for j in arr:
			if j % 2 == 1:
				c += 1
		return c * (N - c)


class Solution:

	def countXorPair(self, arr, N):
		cnt = 0
		evcnt = 0
		for i in arr:
			if i % 2 != 0:
				cnt += 1
			else:
				evcnt += 1
		return cnt * evcnt


class Solution:

	def countXorPair(self, arr, N):
		i = j = 0
		for k in arr:
			if k % 2 == 0:
				i += 1
			else:
				j += 1
		return i * j


class Solution:

	def countXorPair(self, arr, N):
		s = 0
		for i in arr:
			if i % 2 != 0:
				s += 1
		a = N - s
		return a * s


class Solution:

	def countXorPair(self, arr, N):
		ev = 0
		od = 0
		for ele in arr:
			if ele & 1 == 0:
				ev += 1
			else:
				od += 1
		return ev * od


class Solution:

	def countXorPair(self, arr, N):
		a = 0
		for i in range(N):
			if arr[i] % 2 == 0:
				a = a + 1
		b = N - a
		return a * b
if __name__ == '__main__':
	t = int(input())
	for _ in range(0, t):
		n = int(input())
		a = list(map(int, input().split()))
		ob = Solution()
		ans = ob.countXorPair(a, n)
		print(ans)


class Solution:

	def countXorPair(self, a, n):
		e = 0
		for x in a:
			if x % 2 == 0:
				e += 1
		o = n - e
		return o * e
if __name__ == '__main__':
	t = int(input())
	for _ in range(0, t):
		n = int(input())
		a = list(map(int, input().split()))
		ob = Solution()
		ans = ob.countXorPair(a, n)
		print(ans)


class Solution:

	def countXorPair(self, arr, N):
		even = 0
		odd = 0
		for x in range(N):
			if arr[x] % 2 != 0:
				odd += 1
			else:
				even += 1
		return odd * even
if __name__ == '__main__':
	t = int(input())
	for _ in range(0, t):
		n = int(input())
		a = list(map(int, input().split()))
		ob = Solution()
		ans = ob.countXorPair(a, n)
		print(ans)


class Solution:

	def countXorPair(self, arr, N):
		counteven = 0
		countodd = 0
		for itr in range(N):
			if arr[itr] % 2 == 0:
				counteven += 1
			else:
				countodd += 1
		return counteven * countodd
if __name__ == '__main__':
	t = int(input())
	for _ in range(0, t):
		n = int(input())
		a = list(map(int, input().split()))
		ob = Solution()
		ans = ob.countXorPair(a, n)
		print(ans)


class Solution:

	def countXorPair(self, arr, N):
		x = 0
		for i in arr:
			if i % 2 == 0:
				x += 1
		y = N - x
		return x * y


class Solution:

	def countXorPair(self, arr, n):
		even = []
		odd = []
		for x in arr:
			if x % 2 == 0:
				even.append(x)
			else:
				odd.append(x)
		return len(even) * len(odd)


class Solution:

	def countXorPair(self, arr, N):
		m = 0
		n = 0
		for i in range(N):
			if arr[i] % 2 == 0:
				m += 1
			else:
				n += 1
		if n >= 1 and m >= 1:
			return m * n
		else:
			return '0'


class Solution:

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


class Solution:

	def countXorPair(self, arr, N):
		evenCount = 0
		oddCount = 0
		for i in range(N):
			if arr[i] % 2 == 0:
				evenCount += 1
			else:
				oddCount += 1
		return oddCount * evenCount


class Solution:

	def countXorPair(self, arr, N):
		ec = 0
		oc = 0
		for i in arr:
			if i % 2 == 0:
				ec += 1
			else:
				oc += 1
		return ec * oc


class Solution:

	def countXorPair(self, arr, N):
		evenCount = 0
		for x in arr:
			if x % 2 == 0:
				evenCount += 1
		return evenCount * (N - evenCount)