Given an Array of Integers Arr of length N, you have to count number of elements of the array that can be counted as pair of equal elements.
 
Example 1: 
Input : 
N = 7
Arr[] = {10, 10, 10, 20, 20, 10, 20}
Output:
6
Explanation:
The pairs formed are: (10,10),
(10,10), (20,20). The leftover 10
can't be paired with any other 10.
So, the Output is 6.
Example 2: 
Input : 
N = 4
Arr = {10, 20, 30, 40}
Output:
0
Explanation:
No pairs can be formed.
So, the Output is 0.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function getTwinCount() which takes an Integer N and an Array Arr as input and returns the answer.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1 <= N <= 10^{5}
1 ≤ Arr[i] ≤ 10^{5}

Difficulty: EASY
Tags: String algorithms

Data structures

Mathematics
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Starter code:
class Solution:

    def getTwinCount(self, N , Arr):

        # code here 

Solutions:
class Solution:

	def getTwinCount(self, N, Arr):
		m = [0] * 100001
		for i in range(N):
			m[Arr[i]] += 1
		r = 0
		for i in range(1, 100001):
			r += m[i] // 2
		r *= 2
		return r


from collections import Counter

class Solution:

	def getTwinCount(self, n, arr):
		k = Counter(arr)
		p = k.values()
		l = []
		for i in p:
			if i % 2 == 0:
				l.append(i)
			else:
				l.append(i - 1)
		return sum(l)


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		c = 0
		k = 0
		for i in Arr:
			d[i] = 0
		for i in Arr:
			d[i] = d[i] + 1
		for i in d:
			c = d[i]
			if d[i] % 2 == 0:
				k = k + d[i]
			else:
				k = k + d[i] - 1
		return k


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		for i in Arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		a = []
		for i in d:
			a.append(int(d[i] / 2))
		return 2 * sum(a)


class Solution:

	def getTwinCount(self, N, Arr):
		c = 0
		freq = {}
		for i in Arr:
			if i not in freq:
				freq[i] = 0
			freq[i] += 1
		for i in freq:
			if freq[i] % 2 == 0:
				c += freq[i]
			else:
				c += freq[i] - 1
		return c


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		for i in Arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		count = 0
		for j in d:
			count += d[j] // 2
		return count * 2


class Solution:

	def getTwinCount(self, N, arr):
		table = {}
		for i in arr:
			if i in table:
				table[i] += 1
			else:
				table[i] = 1
		count = 0
		for j in table:
			count += table[j] // 2
		return count * 2


from collections import Counter

class Solution:

	def getTwinCount(self, N, Arr):
		a = Counter(Arr)
		out = 0
		for i in a.values():
			out += i // 2
		return out * 2


class Solution:

	def getTwinCount(self, N, Arr):
		(c, res) = ([0] * 1000001, 0)
		for i in range(N):
			c[Arr[i]] += 1
		print
		for i in range(1, 100001):
			res += c[i] // 2
		return 2 * res


class Solution:

	def getTwinCount(self, N, Arr):
		counter = {}
		for i in range(N):
			if Arr[i] in counter:
				counter[Arr[i]] += 1
			else:
				counter[Arr[i]] = 1
		for j in counter.values():
			if j % 2 != 0:
				N -= 1
		return N


class Solution:

	def getTwinCount(self, N, arr):
		d = {}
		for ele in arr:
			d[ele] = 0
		for ele in arr:
			d[ele] = d[ele] + 1
		c = 0
		for (k, v) in d.items():
			if v % 2 == 0:
				c = c + v
			else:
				c = c + (v - 1)
		return c


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		count = 0
		for item in Arr:
			if item in d:
				del d[item]
				count += 2
			else:
				d[item] = 1
		return count


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		c = 0
		for i in Arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for i in d.keys():
			if d[i] % 2 == 0:
				c += d[i]
			elif d[i] > 2 and d[i] % 2 != 0:
				c += d[i] - 1
		return c


from collections import Counter

class Solution:

	def getTwinCount(self, N, Arr):
		m = Counter(Arr)
		c = 0
		l = []
		for (keys, values) in m.items():
			c = c + values // 2
		return c * 2


class Solution:

	def getTwinCount(self, N, Arr):
		l = [0] * (max(Arr) + 1)
		cont = 0
		for i in Arr:
			l[i] += 1
		for i in l:
			cont = cont + i // 2
		return cont * 2


class Solution:

	def getTwinCount(self, N, Arr):
		h = {}
		for i in Arr:
			if i not in h:
				h[i] = 1
			else:
				h[i] += 1
		c = 0
		for i in h:
			c = c + h[i] // 2
		return c * 2
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		Arr = list(map(int, input().split()))
		ob = Solution()
		print(ob.getTwinCount(N, Arr))


class Solution:

	def getTwinCount(self, N, Arr):
		mp = [0] * 100001
		for i in range(N):
			mp[Arr[i]] += 1
		ret = 0
		for i in range(1, 100001):
			ret += mp[i] // 2
		ret *= 2
		return ret


class Solution:

	def getTwinCount(self, N, Arr):
		Dict_ = {}
		for i in range(N):
			if Arr[i] not in Dict_:
				Dict_[Arr[i]] = 1
			else:
				Dict_[Arr[i]] += 1
		cnt = 0
		for (key, val) in Dict_.items():
			if val > 1:
				cnt += 2 * (val // 2)
		return cnt


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		ct = 0
		for i in Arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		c = d.values()
		for i in c:
			ct += i // 2
		return ct * 2


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		for x in Arr:
			d[x] = d.get(x, 0) + 1
		pair = 0
		for k in d:
			p = d[k] // 2
			pair += 2 * p
		return pair


class Solution:

	def getTwinCount(self, N, Arr):
		freq = [0] * 100001
		for i in range(N):
			freq[Arr[i]] += 1
		ans = 0
		for i in range(1, 100001):
			ans += freq[i] // 2
		ans *= 2
		return ans


class Solution:

	def getTwinCount(self, N, Arr):
		dic = {}
		k = 0
		for i in Arr:
			try:
				dic[i] += 1
			except:
				dic[i] = 1
		for i in dic:
			k += dic[i] // 2
		return k * 2


class Solution:

	def getTwinCount(self, N, Arr):
		d = dict().fromkeys(Arr, 0)
		for j in Arr:
			d[j] += 1
		c = 0
		for j in d.values():
			c += j // 2 * 2
		return c


class Solution:

	def getTwinCount(self, N, arr):
		count = 0
		d = {}
		for i in arr:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for i in d.values():
			count += i // 2
		return count * 2


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		for i in Arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		pairs = 0
		for i in d.keys():
			if d[i] >= 2:
				pairs += d[i] // 2
		return pairs * 2


class Solution:

	def getTwinCount(self, N, Arr):
		d = {}
		for i in Arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		ans = 0
		for i in d.values():
			ans += i // 2 * 2
		return ans