Given an array Arr of N integers that contains odd number of occurrences for all numbers except for a few elements which are present even number of times. Find the elements which have even occurrences in the array.
Example 1:
Input:
N = 11
Arr[] = {9, 12, 23, 10, 12, 12, 
15, 23, 14, 12, 15}
Output: 12 15 23
Example 2:
Input:
N = 5
Arr[] = {23, 12, 56, 34, 32}
Output: -1
Explanation: Every integer is present odd 
number of times.
Your Task:
You don't need to read input or print anything. Your task is to complete the function repeatingEven() which takes the array of integers arr and its size n as input parameters and returns a sorted array denoting the answer. If no such even occuring element is present return -1.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5}
0 ≤ Arr[i] ≤ 63

Difficulty: EASY
Tags: Bit manipulation

Data structures
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 repeatingEven(self, arr, n):

        # code here

Solutions:
from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		if len(set(arr)) == n:
			return [-1]
		a = Counter(arr)
		r = [key for (key, value) in a.items() if value % 2 == 0]
		r.sort()
		if len(r) != 0:
			return r
		else:
			return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		v = [0] * 64
		ret_arr = set()
		for i in arr:
			v[i] += 1
		for i in arr:
			if v[i] % 2 == 0:
				ret_arr.add(i)
		if len(ret_arr):
			ans = list(ret_arr)
			ans.sort()
			return ans
		return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		l = []
		for i in set(arr):
			if arr.count(i) % 2 == 0:
				l.append(i)
		if len(l) == 0:
			return [-1]
		l.sort()
		return l


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		b = []
		for i in d:
			if d[i] % 2 == 0:
				b.append(i)
		if len(b) > 0:
			b.sort()
			return b
		else:
			return [-1]


from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		d = Counter(arr)
		t = []
		for (i, j) in d.items():
			if j % 2 == 0:
				t.append(i)
		if t == []:
			return [-1]
		t = sorted(t)
		return t


import collections

class Solution:

	def repeatingEven(self, arr, n):
		dict1 = collections.Counter(arr)
		p = []
		for i in arr:
			if dict1[i] % 2 == 0:
				if i not in p:
					p.append(i)
		if p:
			return sorted(p)
		return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		ans = []
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for i in d:
			if d[i] % 2 == 0:
				ans.append(i)
		if len(ans) == 0:
			return [-1]
		return sorted(ans)


class Solution:

	def repeatingEven(self, arr, n):
		s = set(arr)
		b = []
		for i in s:
			if arr.count(i) % 2 == 0:
				b.append(i)
		if len(b) == 0:
			return [-1]
		else:
			return sorted(b)


class Solution:

	def repeatingEven(self, arr, n):
		s = {}
		for i in arr:
			if i in s:
				s[i] += 1
			else:
				s[i] = 1
		count = []
		for i in s:
			if s[i] % 2 == 0:
				count.append(i)
		count.sort()
		if len(count) == 0:
			return [-1]
		else:
			return count


class Solution:

	def repeatingEven(self, arr, n):
		axor = 0
		for i in range(0, n):
			pos = 1 << arr[i]
			axor ^= pos
		res = []
		for i in range(0, n - 1):
			pos = 1 << arr[i]
			if not pos & axor:
				res.append(arr[i])
				axor ^= pos
		if res == []:
			return (-1,)
		res.sort()
		return res


class Solution:

	def repeatingEven(self, arr, n):
		dict_ = {}
		for elem in arr:
			dict_.update({elem: dict_.get(elem, 0) + 1})
		result = sorted([key for (key, value) in dict_.items() if value % 2 == 0])
		return result if result else [-1]


from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		c = Counter(arr)
		ans = [k for k in c if c[k] % 2 == 0]
		ans.sort()
		if len(ans) == 0:
			return [-1]
		return ans


from collections import *

class Solution:

	def repeatingEven(self, arr, n):
		if len(list(set(arr))) == len(arr):
			return [-1]
		a = Counter(arr)
		res = [key for (key, val) in a.items() if val % 2 == 0]
		res.sort()
		if len(res) != 0:
			return res
		else:
			return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		v = []
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		arr = set(arr)
		for i in arr:
			if d[i] % 2 == 0:
				v.append(i)
		v.sort()
		if not v:
			return [-1]
		return v


import collections

class Solution:

	def repeatingEven(self, arr, n):
		res = []
		x = collections.Counter(arr)
		for (k, v) in x.items():
			if v % 2 == 0:
				res.append(k)
		if not res:
			return [-1]
		res.sort()
		return res


from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		c = Counter(arr)
		output = []
		for (item, count) in c.items():
			if count % 2 == 0:
				output.append(item)
		return sorted(output) if output else [-1]


class Solution:

	def repeatingEven(self, arr, n):
		from collections import Counter
		f = Counter(arr)
		ans = []
		a1 = set(arr)
		for v in a1:
			if f[v] % 2 == 0:
				ans.append(v)
		if len(ans) == 0:
			return [-1]
		else:
			ans.sort()
			return ans


class Solution:

	def repeatingEven(self, arr, n):
		a = set(arr)
		l = []
		for i in a:
			if arr.count(i) % 2 == 0:
				l.append(i)
		if len(l) > 0:
			res = list(set(l))
			res.sort()
			return res
		else:
			return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		for j in arr:
			if j in d:
				d[j] += 1
			else:
				d[j] = 1
		r = []
		for j in arr:
			if d[j] % 2 == 0:
				if j not in r:
					r.append(j)
		if len(r) == 0:
			return [-1]
		r.sort()
		return r


class Solution:

	def repeatingEven(self, arr, n):
		dic = {}
		for i in arr:
			if i not in dic:
				dic[i] = 1
			else:
				dic[i] += 1
		l = []
		w = []
		for (k, v) in dic.items():
			if v % 2 == 0:
				l.append(k)
		if len(l) == 0:
			return [-1]
		else:
			return sorted(l)


class Solution:

	def repeatingEven(self, a, n):
		d = {}
		a = []
		for i in arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for (k, v) in d.items():
			if v % 2 == 0:
				a.append(k)
		a = sorted(a)
		if len(a) != 0:
			return a
		else:
			return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		a = []
		for i in arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for i in arr:
			if d[i] % 2 == 0:
				a.append(i)
		if len(a) == 0:
			a.append(-1)
		return sorted(set(a))


class Solution:

	def repeatingEven(self, arr, n):
		b = [*set(arr)]
		c = []
		for i in range(0, len(b)):
			if arr.count(b[i]) % 2 == 0:
				c.append(b[i])
		if len(c) > 0:
			c.sort()
			return c
		else:
			d = [-1]
			return d


from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		a = []
		d = Counter(arr)
		for i in d.keys():
			if d[i] % 2 == 0:
				a.append(i)
		b = sorted(a)
		if a:
			return b
		else:
			return [-1]


from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		l = []
		d = dict(Counter(arr))
		k = list(d.keys())
		v = list(d.values())
		for i in range(len(v)):
			if v[i] % 2 == 0:
				l.append(k[i])
		if len(l) > 0:
			return sorted(l)
		return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		f = {}
		c = []
		for i in arr:
			if i in f:
				f[i] += 1
			else:
				f[i] = 1
		for i in f:
			if f[i] % 2 == 0:
				c.append(i)
		if len(c) == 0:
			return [-1]
		return sorted(c)


class Solution:

	def repeatingEven(self, arr, n):
		(D, K) = ({}, [])
		for i in arr:
			if i in D:
				D[i] += 1
			else:
				D[i] = 1
		for i in D:
			if D[i] % 2 == 0:
				K.append(i)
		if K == []:
			return [-1]
		return sorted(K)


class Solution:

	def repeatingEven(self, arr, n):
		h = set()
		r = [i for i in arr if not (i in h or h.add(i))]
		d = dict()
		for i in arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		m = []
		t = []
		for i in d:
			if d[i] % 2 == 0:
				m.append(i)
		for i in r:
			if i in m:
				t.append(i)
		if len(m) == 0:
			return [-1]
		return sorted(t)


class Solution:

	def repeatingEven(self, arr, n):
		dic = {}
		for i in range(n):
			dic[arr[i]] = dic.get(arr[i], 0) + 1
		ans = []
		for (key, value) in dic.items():
			if value % 2 == 0:
				ans.append(key)
		return [-1] if len(ans) == 0 else sorted(ans)


class Solution:

	def repeatingEven(self, arr: list, n: int) -> list:
		counter = {x: 0 for x in range(0, 64)}
		for i in range(n):
			counter[arr[i]] += 1
		even_occuring = [k for (k, v) in counter.items() if v != 0 and v % 2 == 0]
		return even_occuring if even_occuring else [-1]


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		l = []
		for i in arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for i in d:
			if d[i] % 2 == 0:
				l.append(i)
		if l == []:
			return [-1]
		else:
			return sorted(l)


class Solution:

	def repeatingEven(self, arr, n):
		d = dict()
		res = []
		for i in arr:
			d[i] = d.get(i, 0) + 1
		for i in sorted(d):
			if d[i] % 2 == 0:
				res.append(i)
		if not res:
			return [-1]
		return res


class Solution:

	def repeatingEven(self, arr, n):
		a = dict()
		b = []
		for i in arr:
			a[i] = a.get(i, 0) + 1
		for i in sorted(a):
			if a[i] % 2 == 0:
				b.append(i)
		if not b:
			return [-1]
		return b


class Solution:

	def repeatingEven(self, arr, n):
		dic = {}
		lis = []
		for i in arr:
			if i not in dic:
				dic[i] = 1
			else:
				dic[i] += 1
		for i in dic:
			if dic[i] % 2 == 0:
				lis.append(i)
		if len(lis) == 0:
			lis.append(-1)
		lis.sort()
		return lis


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		l = []
		for i in arr:
			if i not in d:
				d[i] = d.get(i, 0) + 1
			else:
				d[i] += 1
		for (k, v) in d.items():
			if v % 2 == 0:
				l.append(k)
		l.sort()
		if len(l) != 0:
			return l
		else:
			return [-1]


from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		m = Counter(arr)
		l = []
		p = [-1]
		for (keys, values) in m.items():
			if values % 2 == 0:
				l.append(keys)
		l.sort()
		if l:
			return l
		else:
			return p


class Solution:

	def repeatingEven(self, arr, n):
		dict = {}
		for i in arr:
			dict[i] = dict.get(i, 0) + 1
		final = []
		for (key, value) in dict.items():
			if value % 2 == 0:
				final.append(key)
		return sorted(final) if final else [-1]


class Solution:

	def repeatingEven(self, arr, n):
		z = {}
		for i in arr:
			if i not in z:
				z[i] = 1
			else:
				z[i] += 1
		f = []
		for i in z:
			if z[i] % 2 == 0:
				f.append(i)
		if f:
			return sorted(f)
		return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		dic = {}
		for i in range(n):
			if arr[i] in dic.keys():
				dic[arr[i]] += 1
			else:
				dic[arr[i]] = 1
		res = []
		c = 0
		for i in dic:
			if dic[i] % 2 == 0:
				c += 1
				res.append(i)
		if c == 0:
			return [-1]
		res.sort()
		return res


from collections import Counter

class Solution:

	def repeatingEven(self, arr, n):
		di = Counter(arr)
		li = []
		for i in di.keys():
			if di[i] % 2 == 0:
				li.append(i)
		li.sort()
		return li if len(li) > 0 else (-1,)


class Solution:

	def repeatingEven(self, arr, n):
		dis = {}
		for x in arr:
			if x in dis:
				dis[x] += 1
			else:
				dis[x] = 1
		res = sorted([k for (k, v) in dis.items() if v % 2 == 0])
		return res if len(res) > 0 else [-1]


class Solution:

	def repeatingEven(self, arr, n):
		list1 = []
		d = {}
		for ele in arr:
			if ele in d:
				d[ele] += 1
			else:
				d[ele] = 1
		for (ele, value) in d.items():
			if value & 1 == 0:
				list1.append(ele)
		if not list1:
			return [-1]
		else:
			list1.sort()
			return list1


class Solution:

	def repeatingEven(self, arr, n):
		ans = 0
		final = []
		for i in arr:
			pos = 1 << i
			ans = ans ^ pos
		for i in arr:
			pos = 1 << i
			if not pos & ans:
				final.append(i)
				ans = ans ^ pos
		if len(final) > 0:
			return sorted(final)
		else:
			return [-1]


class Solution:

	def repeatingEven(self, arr, n):
		if n <= 1:
			return -1
		freq = {}
		for i in range(n):
			if arr[i] not in freq:
				freq[arr[i]] = 1
			else:
				freq[arr[i]] += 1
		new_arr = []
		for i in freq:
			if freq[i] % 2 == 0:
				new_arr.append(i)
		if len(new_arr) == 0:
			return [-1]
		else:
			new_arr.sort()
			return new_arr


from collections import OrderedDict

class Solution:

	def repeatingEven(self, arr, n):
		k = OrderedDict()
		for x in arr:
			if x in k.keys():
				k[x] += 1
			else:
				k[x] = 1
		ret = []
		for x in k:
			if k[x] % 2 == 0:
				ret.append(x)
		if len(ret) == 0:
			return [-1]
		else:
			ret.sort()
			return ret


class Solution:

	def repeatingEven(self, arr, n):
		size = 64
		count = [0] * size
		res = []
		for i in range(n):
			pos = arr[i]
			count[pos] += 1
		for i in range(size):
			if count[i] > 0 and count[i] % 2 == 0:
				res.append(i)
		if len(res) == 0:
			res.append(-1)
			return res
		return res


class Solution:

	def repeatingEven(self, arr, n):
		d = {}
		m = []
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for i in d:
			if d[i] % 2 == 0:
				m.append(i)
		if len(m) == 0:
			return [-1]
		return sorted(m)
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		n = int(input())
		arr = list(map(int, input().strip().split()))
		ob = Solution()
		ans = ob.repeatingEven(arr, n)
		for xx in ans:
			print(xx, end=' ')
		print()
		tc -= 1


class Solution:

	def repeatingEven(self, arr, n):
		s = {}
		for i in arr:
			if i in s:
				s[i] += 1
			else:
				s[i] = 1
		b = []
		for i in s:
			if s[i] % 2 == 0:
				b.append(i)
		if len(b) == 0:
			return [-1]
		b.sort()
		return b
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		n = int(input())
		arr = list(map(int, input().strip().split()))
		ob = Solution()
		ans = ob.repeatingEven(arr, n)
		for xx in ans:
			print(xx, end=' ')
		print()
		tc -= 1


class Solution:

	def repeatingEven(self, arr, n):
		dic = {}
		for itr in range(n):
			if arr[itr] not in dic.keys():
				dic[arr[itr]] = 1
			else:
				dic[arr[itr]] += 1
		res = []
		for itr in dic.keys():
			if dic[itr] % 2 == 0:
				res.append(itr)
		res.sort()
		if len(res) != 0:
			return res
		return [-1]
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		n = int(input())
		arr = list(map(int, input().strip().split()))
		ob = Solution()
		ans = ob.repeatingEven(arr, n)
		for xx in ans:
			print(xx, end=' ')
		print()
		tc -= 1