Given an array of distinct integers, write a program to find if there exist two pairs (a, b) and (c, d) such that ab = cd, where a, b, c and d are distinct elements. If such pairs exists then print 1 else -1.
 
Example 1:
Input:
N=7
arr[] = {3, 4, 7, 1, 2, 9, 8} 
Output: 1
Explanation:
Product of 4 and 2 is 8 and also,
the product of 1 and 8 is 8.  
 
Example 2:
Input:
N=6
arr[] = {1, 6, 3, 9, 2, 10} 
Output: 1
Your Task:
Since, 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 findPairs() that takes array arr and n  as parameters and return 1 if any such pair is found otherwise return -1. 
 
Expected Time Complexity: O(N^{2}).
Expected Auxiliary Space: O(N^{2}).
 
Constraints:
1 ≤ N ≤ 10^{3}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(N^{2}).
Expected Auxiliary Space: O(N^{2}).

Starter code:
#User function Template for python3

class Solution:
    def findPairs(self,a,n):
        #code here.


Solutions:
class Solution:

	def findPairs(self, arr, n):
		H = dict()
		for i in range(n):
			for j in range(i + 1, n):
				prod = arr[i] * arr[j]
				if prod not in H.keys():
					H[prod] = [i, j]
				else:
					return 1
		return -1


class Solution:

	def findPairs(self, a, n):
		s = set()
		for i in range(n):
			for j in range(i + 1, n):
				mul = a[i] * a[j]
				if mul in s:
					return 1
					break
				else:
					s.add(mul)
		return -1


class Solution:

	def findPairs(self, a, n):
		d = {}
		for i in range(n - 1):
			for j in range(i + 1, n):
				if a[i] * a[j] in d:
					return 1
				else:
					d[a[i] * a[j]] = 1
		return -1


class Solution:

	def findPairs(self, arr, n):
		mapp = {}
		for i in range(n):
			for j in range(i + 1, n):
				(a, b) = (arr[i], arr[j])
				if a != b:
					if a * b not in mapp:
						mapp[a * b] = 1
					else:
						return 1
		return -1


class Solution:

	def findPairs(self, a, n):
		dict = {}
		for i in range(n):
			for j in range(i + 1, n):
				value1 = a[i] * a[j]
				dict[value1] = dict.get(value1, 0) + 1
				if dict[value1] > 1:
					return 1
		return -1


class Solution:

	def findPairs(self, a, n):
		dic = {}
		for i in range(n - 1):
			for j in range(i + 1, n):
				k = a[i] * a[j]
				if k not in dic:
					dic[k] = 1
				else:
					dic[k] += 1
				if dic[k] >= 2:
					return 1
		return -1


class Solution:

	def findPairs(self, a, n):
		res = []
		for i in range(n - 1):
			for j in range(i + 1, n):
				if a[i] * a[j] not in res:
					res.append(a[i] * a[j])
				else:
					return 1
		return -1


from itertools import combinations

class Solution:

	def findPairs(self, a, n):
		count = 0
		x = [i for i in range(len(a))]
		y = []
		for (i, j) in combinations(x, 2):
			y.append(a[i] * a[j])
			count += 1
			if count > 10000:
				break
		if len(y) != len(set(y)):
			return 1
		return -1


class Solution:

	def findPairs(self, a, n):
		listed = {}
		for i in range(n):
			for j in range(i + 1, n):
				x = a[i] * a[j]
				if x in listed:
					return 1
				else:
					listed[x] = 1
		return -1


class Solution:

	def findPairs(self, a, n):
		arr = a
		found = False
		H = dict()
		for i in range(n):
			for j in range(i + 1, n):
				prod = arr[i] * arr[j]
				if prod not in H.keys():
					H[prod] = [i, j]
				else:
					pp = H[prod]
					found = True
					return 1
		return -1


class Solution:

	def findPairs(self, a, n):
		d = dict()
		for i in range(n):
			for j in range(i + 1, n):
				prod = a[i] * a[j]
				if prod not in d.keys():
					d[prod] = [i, j]
				else:
					return 1
		return -1


class Solution:

	def findPairs(self, a, n):
		dic = {}
		for i in range(n):
			for j in range(i + 1, n):
				product = a[i] * a[j]
				if product in dic:
					return 1
				else:
					dic[product] = (a[i], a[j])
		return -1


class Solution:

	def findPairs(self, arr, n):
		map = {}
		for i in range(n):
			for j in range(i + 1, n):
				prod = arr[i] * arr[j]
				if prod in map:
					return 1
				else:
					map[prod] = (arr[i], arr[j])
		return -1