Given two arrays A[] and B[] consisting of N and M elements respectively. The task is to find minimum number of elements to remove from each array such that no common element exist in both the arrays.
 
Example 1:
Input :
A[] = { 2, 3, 4, 5, 8 }
B[] = { 1, 2, 3, 4}
Output :
3
Explanation:
We need to remove 2, 3 and 4 from any 
array.
 
Example 2:
Input :
A[] = { 4, 2, 4, 4}
B[] = { 4, 3 }
Output :
1
Explanation:
We need to remove 4 from B[]
 
Example 3:
Input:
A[] = { 1, 2, 3, 4 }
B[] = { 5, 6, 7 }
Output:
0
Explanation:
There is no common element in both.
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function minRemove() which takes the array A[], B[] and its size N, M as inputs and returns the minimum number of elements to be deleted.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1<=N,M<=10^{5}
1<=A[i],B[i]<=10^{5}

Difficulty: EASY
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Starter code:
#User function Template for python3

class Solution:
    def minRemove(self, a, b, n, m):
        #Code here
    
    
    

Solutions:
class Solution:

	def minRemove(self, a, b, n, m):
		from collections import Counter
		s1 = set(a)
		s2 = set(b)
		arr = s1.intersection(s2)
		ans = 0
		c1 = Counter(a)
		c2 = Counter(b)
		for v in arr:
			ans += min(c1[v], c2[v])
		return ans


class Solution:

	def minRemove(self, a, b, n, m):
		res = set(a) & set(b)
		count = 0
		d_a = {}
		d_b = {}
		for elem in a:
			d_a.update({elem: d_a.get(elem, 0) + 1})
		for elem in b:
			d_b.update({elem: d_b.get(elem, 0) + 1})
		res = list(res)
		for index in range(len(res)):
			count += min(d_a[res[index]], d_b[res[index]])
		return count


class Solution:

	def minRemove(self, a, b, n, m):
		countA = {}
		countB = {}
		for i in range(n):
			if a[i] in countA:
				countA[a[i]] += 1
			else:
				countA[a[i]] = 1
		for i in range(m):
			if b[i] in countB:
				countB[b[i]] += 1
			else:
				countB[b[i]] = 1
		c = 0
		for i in countA:
			if i in countB:
				c += min(countA[i], countB[i])
		return c


class Solution:

	def minRemove(self, a, b, n, m):
		t = set(a).intersection(set(b))
		d1 = {}
		for i in a:
			if i in d1:
				d1[i] += 1
			else:
				d1[i] = 1
		d2 = {}
		for i in b:
			if i in d2:
				d2[i] += 1
			else:
				d2[i] = 1
		c = 0
		for i in t:
			c += min(d1[i], d2[i])
		return c


class Solution:

	def minRemove(self, a, b, n, m):
		c_a = {}
		c_b = {}
		c = 0
		for i in a:
			if i in c_a:
				c_a[i] += 1
			else:
				c_a[i] = 1
		for i in b:
			if i in c_b:
				c_b[i] += 1
			else:
				c_b[i] = 1
		for i in c_a:
			if i in c_b.keys():
				c += min(c_a[i], c_b[i])
		return c


class Solution:

	def minRemove(self, a, b, n, m):
		countA = dict()
		countB = dict()
		for i in range(n):
			countA[a[i]] = countA.get(a[i], 0) + 1
		for i in range(m):
			countB[b[i]] = countB.get(b[i], 0) + 1
		res = 0
		for x in countA:
			if x in countB.keys():
				res += min(countA[x], countB[x])
		return res


class Solution:

	def minRemove(self, a, b, n, m):
		d1 = {}
		for i in a:
			if i in d1:
				d1[i] += 1
			else:
				d1[i] = 1
		d2 = {}
		for i in b:
			if i in d2:
				d2[i] += 1
			else:
				d2[i] = 1
		count = 0
		for i in d1:
			if i in d2:
				count += min(d1[i], d2[i])
		return count


class Solution:

	def minRemove(self, a, b, n, m):
		d = {}
		for i in a:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		s = {}
		for i in b:
			if i in s:
				s[i] += 1
			else:
				s[i] = 1
		c = 0
		for i in d:
			if i in s:
				c += min(d[i], s[i])
		return c


class Solution:

	def minRemove(self, a, b, n, m):
		i = c = j = 0
		a.sort()
		b.sort()
		while i < n and j < m:
			if a[i] < b[j]:
				i += 1
			elif a[i] > b[j]:
				j += 1
			else:
				c += 1
				i += 1
				j += 1
		return c


class Solution:

	def minRemove(self, a, b, n, m):
		hashA = {}
		c = 0
		for i in a:
			if i in hashA:
				hashA[i] += 1
			else:
				hashA[i] = 1
		hashB = {}
		for i in b:
			if i in hashB:
				hashB[i] += 1
			else:
				hashB[i] = 1
		for i in hashA:
			if i in hashB:
				c += min(hashA[i], hashB[i])
		return c


from collections import Counter

class Solution:

	def minRemove(self, a, b, n, m):
		c1 = Counter(a)
		c2 = Counter(b)
		return sum((min(c1[item], c2[item]) for item in c1))


class Solution:

	def minRemove(self, a, b, n, m):
		dict1 = {}
		dict2 = {}
		for element in a:
			dict1[element] = dict1.get(element, 0) + 1
		for element in b:
			dict2[element] = dict2.get(element, 0) + 1
		count = 0
		for element in dict1:
			if element in dict2:
				if dict1[element] == dict2[element]:
					count += dict2[element]
				if dict1[element] > dict2[element]:
					count += dict2[element]
				if dict1[element] < dict2[element]:
					count += dict1[element]
		return count


class Solution:

	def minRemove(self, a, b, n, m):
		(dic1, dic2) = ({}, {})
		for item in a:
			dic1[item] = dic1.get(item, 0) + 1
		for item in b:
			dic2[item] = dic2.get(item, 0) + 1
		count = 0
		for (key, value) in dic1.items():
			if key in dic2:
				minValue = min(value, dic2[key])
				count += minValue
		return count


class Solution:

	def minRemove(self, a, b, n, m):
		dict = {}
		for i in a:
			dict[i] = dict.get(i, 0) + 1
		count = 0
		for j in b:
			if j in dict and dict[j] != 0:
				count += 1
				dict[j] -= 1
		return count


class Solution:

	def minRemove(self, a, b, n, m):
		di = dict()
		for i in a:
			if i not in di:
				di[i] = 1
			else:
				di[i] += 1
		j = 0
		for i in b:
			if i in di:
				j += 1
				di[i] -= 1
				if di[i] == 0:
					del di[i]
		return j


class Solution:

	def minRemove(self, a, b, n, m):
		dict_a = {}
		dict_b = {}
		ans = 0
		for num in a:
			if num in dict_a:
				dict_a[num] += 1
			else:
				dict_a[num] = 1
		for num in b:
			if num in dict_b:
				dict_b[num] += 1
			else:
				dict_b[num] = 1
		for num in dict_a:
			if num in dict_b:
				ans += min(dict_a[num], dict_b[num])
		return ans


class Solution:

	def minRemove(self, a, b, n, m):
		da = {}
		db = {}
		for i in a:
			da[i] = da.get(i, 0) + 1
		for i in b:
			db[i] = db.get(i, 0) + 1
		ans = 0
		for i in db:
			if i in da:
				ans += min(da[i], db[i])
		return ans


class Solution:

	def minRemove(self, arr, brr, n, m):
		d1 = {}
		d2 = {}
		for i in arr:
			if i not in d1:
				d1[i] = 1
			else:
				d1[i] += 1
		for i in brr:
			if i not in d2:
				d2[i] = 1
			else:
				d2[i] += 1
		res = 0
		for (i, j) in d1.items():
			if i in d2:
				if d1[i] > d2[i]:
					res += d2[i]
				else:
					res += d1[i]
		return res