Given an array arr[] of size N of distinct elements and a number X, find if there is a pair in arr[] with product equal to X.
Example 1:
Input:
N = 4, X = 400
arr[] = {10, 20, 9, 40}
Output: Yes
Explanation: As 10 * 40 = 400.
Example 2:
Input:
N = 4, X = 30
arr[] = {-10, 20, 9, -40}
Output: No
Explanation: No pair with product 30.
Your Task:
You don't need to read input or print anything. Your task is to complete the function isProduct() which takes the arr[], n and x as input parameters and returns an boolean value denoting the answer.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 10^{5}
0 ≤ |arr_{i}| ≤ 10^{8}
0 ≤ X ≤ 10^{18}

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 isProduct(self, arr, n, x):
        # code here

Solutions:
class Solution:

	def isProduct(self, arr, n, x):
		for i in range(n):
			if arr[i] != 0 and x % arr[i] == 0 and (x // arr[i] in arr):
				return True
		else:
			return False


class Solution:

	def isProduct(self, arr, n, x):
		arr.sort()
		dic = {}
		for i in range(n):
			if arr[i] not in dic:
				if arr[i] != 0:
					if x % arr[i] == 0:
						dic[x // arr[i]] = 1
		for i in arr:
			if i in dic:
				return 1
		return 0


class Solution:

	def isProduct(self, arr, n, x):
		complements = set()
		for i in range(n):
			if arr[i] == 0:
				continue
			if x % arr[i] == 0:
				complement = x // arr[i]
				if complement in complements:
					return True
				complements.add(arr[i])
		return False
		return False


class Solution:

	def isProduct(self, arr, n, x):
		divi = set()
		for el in arr:
			if el == 0:
				if x == 0:
					return True
				else:
					continue
			if x % el == 0:
				oth = x // el
				if oth in divi:
					return True
				divi.add(el)
		return False


class Solution:

	def isProduct(self, arr, n, x):
		st = set()
		for i in arr:
			if i != 0 and x / i in st:
				return True
			else:
				st.add(i)


from collections import Counter

class Solution:

	def isProduct(self, arr, n, x):
		map = Counter(arr)
		for i in arr:
			if i != 0:
				s = x // i
				if s in map and s * i == x:
					return True
					break
		return False


class Solution:

	def isProduct(self, arr, n, x):
		d = {}
		if x == 0 and arr.count(0):
			return True
		for elem in arr:
			if elem != 0 and x / elem in d:
				return True
			else:
				d[elem] = 0
		return False


class Solution:

	def isProduct(self, arr, n, x):
		myset = set()
		for i in range(n):
			if arr[i] == 0:
				if x == 0:
					return True
				else:
					continue
			if x / arr[i] in myset:
				return True
			else:
				myset.add(arr[i])
		return False


class Solution:

	def isProduct(self, arr, n, x):
		mp = dict()
		for i in arr:
			if i in mp.keys():
				mp[i] += 1
			else:
				mp[i] = 1
		for i in arr:
			if i != 0:
				res = x / i
				if res in mp.keys():
					mp[i] -= 1
					if mp[i] == 0:
						mp.pop(i)
					return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		dictA = {}
		for i in arr:
			dictA[i] = 0
		for i in arr:
			if i != 0 and x % i == 0 and (i * i != x):
				dictA[i] += 1
				if x // i in dictA.keys():
					dictA[x // i] += 1
		for k in dictA.keys():
			if dictA[k] > 1:
				return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		freq = {}
		for num in arr:
			if num in freq:
				freq[num] += 1
			else:
				freq[num] = 1
		for num in arr:
			if num != 0:
				if x % num == 0:
					quotient = x // num
					if quotient in freq and (quotient != num or freq[quotient] > 1):
						return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		d = dict()
		for i in arr:
			d[i] = i
		for i in arr:
			if i != 0 and x // i in d.keys() and (x // i * i == x):
				return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s = set()
		for i in arr:
			if i != 0 and x / i in s:
				return True
			else:
				s.add(float(i))
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s = set(arr)
		for i in arr:
			if i != 0:
				s.remove(i)
				if x / i in s:
					return True
				s.add(i)
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s = set(arr)
		if x == 0:
			if 0 in s:
				return 1
		for i in range(n):
			if arr[i] != 0:
				s.remove(arr[i])
				a = x / arr[i]
				if a in s:
					return 1
				s.add(arr[i])
		return 0


class Solution:

	def isProduct(self, arr, n, x):
		d = {}
		for i in arr:
			if i in d:
				return True
			elif i != 0:
				d[x / i] = 1
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s1 = set()
		for i in range(n):
			if arr[i] == 0:
				continue
			p = x // arr[i]
			if p in s1 and p * arr[i] == x:
				return True
			s1.add(arr[i])
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s = set()
		for i in arr:
			if i != 0 and x / i in s:
				return 1
			elif i != 0:
				s.add(i)
		return 0


class Solution:

	def isProduct(self, arr, n, x):
		dict1 = dict()
		for i in range(n):
			if dict1 == dict():
				dict1[arr[i]] = 1
			elif arr[i] != 0 and x / arr[i] in dict1:
				return 1
			else:
				dict1[arr[i]] = 1
		return 0


class Solution:

	def isProduct(self, arr, n, k):
		d = dict()
		for x in arr:
			if d.get(x) == None:
				d[x] = 0
			d[x] += 1
		for x in d.keys():
			if x == 0:
				if k == 0:
					return True
				continue
			if k % x == 0:
				x2 = k // x
				if x2 != x:
					if d.get(x2) != None:
						return True
				elif d[x2] > 1:
					return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		d = dict()
		for i in arr:
			if i not in d:
				if i != 0 and x % i == 0:
					d[x / i] = 1
			else:
				return True
		if x == 0:
			if 0 in arr:
				return True
			else:
				return False
		return False


import math

class Solution:

	def isProduct(self, arr, n, x):
		f = {}
		for i in range(n):
			if float(arr[i]) in f:
				f[float(arr[i])] += 1
			else:
				f[float(arr[i])] = 1
		for i in range(n):
			if arr[i] != 0:
				y = x / arr[i]
				f[float(arr[i])] -= 1
				if y in f:
					return True
				else:
					f[float(arr[i])] += 1
		return False


class Solution:

	def isProduct(self, arr, n, x):
		from collections import Counter
		mp = Counter(arr)
		for i in arr:
			if i != 0:
				temp = x // i
				if temp in mp and temp * i == x:
					return True
					break
		return False


class Solution:

	def isProduct(self, arr, n, x):
		temp_arr = []
		for i in range(n):
			if arr[i] == 0:
				pass
			elif x % arr[i] == 0:
				temp_arr.append(arr[i])
		for i in temp_arr:
			if x / i in temp_arr:
				return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		from collections import Counter
		mp = Counter(arr)
		for v in arr:
			if v != 0:
				j = x // v
				if j in mp and j * v == x:
					return True
					break
		return False


class Solution:

	def isProduct(self, arr, n, x):
		setti = set(arr)
		for item in arr:
			if item != 0 and item ** 2 != x and (x / item in setti):
				return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s = set()
		for i in range(0, n):
			if arr[i] == 0:
				if x == 0:
					return True
				else:
					continue
			if x % arr[i] == 0:
				if x // arr[i] in s:
					return True
				else:
					s.add(arr[i])
		return False
x = Solution()
arr = [10, 20, 9, 40]
x.isProduct(arr, len(arr), 400)


class Solution:

	def isProduct(self, arr, n, x):
		s = set(arr)
		for i in arr:
			if i != 0:
				if x % i == 0:
					y = x // i
					if y in s:
						return True
			elif x == 0:
				return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		d = {}
		if x == 0:
			for elt in arr:
				if elt == 0:
					return True
			return False
		for elt in arr:
			if elt != 0 and x / elt in d:
				return True
			else:
				d[elt] = 1
		return False


class Solution:

	def isProduct(self, arr, n, x):
		mymap = dict()
		for i in range(n):
			if arr[i] == 0:
				continue
			elif x / arr[i] in mymap:
				return 'Yes'
			else:
				mymap[arr[i]] = i


class Solution:

	def isProduct(self, arr, n, x):
		myset = set()
		for i in range(n):
			if arr[i] == 0:
				continue
			elif x / arr[i] in myset:
				return 'Yes'
			else:
				myset.add(arr[i])


class Solution:

	def isProduct(self, arr, n, x):
		d = {}
		s = 0
		for i in range(n):
			if arr[i] != 0:
				s = x % arr[i]
				if s == 0 and x // arr[i] in d:
					return True
				else:
					d[arr[i]] = 1
			else:
				pass
		else:
			return False


class Solution:

	def isProduct(self, arr, n, x):
		h = {}
		for i in arr:
			if i != 0:
				if x / i not in h:
					h[i] = x / i
				else:
					return True
			elif x == 0:
				return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s = {}
		for i in arr:
			if i in s:
				s[i] += 1
			else:
				s[i] = 1
		for i in range(n):
			if arr[i] != 0:
				dev = x / arr[i]
				if dev == arr[i]:
					if s[dev] > 1:
						return True
				elif dev in s:
					return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		d = {}
		for i in range(n):
			d[arr[i]] = i
		for i in range(n):
			if arr[i] == 0 and x == 0:
				return 1
			if arr[i] != 0:
				if x / arr[i] in d and d[x / arr[i]] != i:
					return 1
		return 0


class Solution:

	def isProduct(self, arr, n, x):
		dict1 = dict(zip(arr, [0] * n))
		for i in range(n):
			if arr[i] != 0:
				if x / arr[i] in dict1:
					return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		l = {}
		for i in arr:
			if i == 0:
				continue
			else:
				k = x / i
				if k in l.keys():
					return 1
				else:
					l[i] = 0
		return 0


from collections import Counter

class Solution:

	def isProduct(self, arr, n, x):
		z = Counter(arr)
		for i in range(len(arr)):
			if arr[i] != 0:
				s = x // arr[i]
			if s in z and s * arr[i] == x:
				return True
		return False


class Solution:

	def isProduct(self, arr, n, x):
		myset = set()
		for i in arr:
			if i != 0:
				j = x // i
				if j in myset and j * i == x:
					return True
				else:
					myset.add(i)
		return False


class Solution:

	def isProduct(self, arr, n, x):
		s = set()
		for i in range(len(arr)):
			if arr[i] != 0:
				if x / arr[i] in s:
					return True
				else:
					s.add(arr[i])


class Solution:

	def isProduct(self, arr, n, x):
		mySet = set()
		for i in arr:
			if i == 0 and x == 0:
				return True
			elif i == 0 and i not in mySet:
				mySet.add(i)
			elif x / i in mySet:
				return True
			else:
				mySet.add(i)
		return False


class Solution:

	def isProduct(self, arr, n, x):
		ds = {}
		for i in arr:
			ds[i] = ds.get(i, 0) + 1
		for i in range(n):
			if arr[i] == 0:
				continue
			rs = x // arr[i]
			if arr[i] * rs == x:
				if rs == arr[i]:
					if ds.get(rs, 0) > 1:
						return True
				elif ds.get(rs, 0) > 0:
					return True
		return False