Given an array of positive integers. The task is to print the minimum product of any two numbers of the given array.
 
Example 1:
Input : n = 4 arr[] = {2, 7, 3, 4}
Output : 6
Explanation : The minimum product of any two numbers
will be 2 * 3 = 6.
 
Example 2:
Input : n = 6 arr[] = {198, 76, 544, 123, 154, 675}
Output :  9348
Explanation : The minimum product of any two numbers
will be 76 * 123 = 9348.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the functionprintMinimumProduct()which takes the array A[] and its size N as inputs and returns the minimum product of two numbers
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
2<=N<=10^{5}
1<=A[i]<=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



class Solution:

    def printMinimumProduct(self, a, n):

        #Code here

    

    

    

Solutions:
class Solution:

	def printMinimumProduct(self, a, n):
		arr = list(map(int, a))
		arr.sort()
		return arr[0] * arr[1]


class Solution:

	def printMinimumProduct(self, a, n):
		l = [int(i) for i in a]
		l.sort()
		return l[0] * l[1]


class Solution:

	def printMinimumProduct(self, a, n):
		a = list(map(int, a))
		(v1, v2) = (a[0], a[1])
		for x in a[2:]:
			(v1, v2, x) = sorted([v1, v2, x])
		return v1 * v2


class Solution:

	def printMinimumProduct(self, a, n):
		arr = [0] * n
		for i in range(n):
			arr[i] = int(a[i])
		arr.sort()
		return arr[0] * arr[1]


class Solution:

	def printMinimumProduct(self, a, n):
		(m1, m2) = (10 ** 5 + 1, 10 ** 5 + 1)
		(i1, i2) = (0, 0)
		a = list(map(int, a))
		for i in range(n):
			if m1 > a[i]:
				m1 = a[i]
				i1 = i
		for i in range(n):
			if m2 > a[i] and a[i] >= m1 and (i != i1):
				m2 = a[i]
		return m1 * m2


class Solution:

	def printMinimumProduct(self, a, n):
		a[:] = [int(x) for x in a]
		a.sort()
		return a[0] * a[1]


class Solution:

	def printMinimumProduct(self, a, n):
		li = []
		for i in a:
			li.append(int(i))
		li.sort()
		return li[0] * li[1]


class Solution:

	def printMinimumProduct(self, arr, n):
		a = b = 100000000.0
		for i in arr:
			if int(i) < a:
				b = a
				a = int(i)
			elif int(i) < b:
				b = int(i)
		return a * b


import numpy

class Solution:

	def printMinimumProduct(self, a, n):
		a = list(map(int, a))
		a.sort()
		return int(a[0]) * int(a[1])


class Solution:

	def printMinimumProduct(self, a, n):
		numbers = []
		for item in a:
			numbers.append(int(item))
		numbers.sort()
		return numbers[0] * numbers[1]


class Solution:

	def printMinimumProduct(self, a, n):
		a = map(int, a)
		a = sorted(a)
		res = int(a[0]) * int(a[1])
		return res


class Solution:

	def printMinimumProduct(self, a, n):
		l = []
		for i in a:
			l.append(int(i))
		l.sort()
		a1 = l[0]
		b1 = l[1]
		res = a1 * b1
		return res


import math

class Solution:

	def printMinimumProduct(self, a, n):
		ls = math.inf
		sls = math.inf
		for num in a:
			num = int(num)
			if num < ls:
				sls = ls
				ls = num
			elif num < sls:
				sls = num
		return ls * sls


class Solution:

	def printMinimumProduct(self, a, n):
		a1 = [int(i) for i in a]
		m1 = min(a1)
		a1.remove(m1)
		m2 = min(a1)
		return int(m1) * int(m2)


import sys

class Solution:

	def printMinimumProduct(self, arr, n):
		for i in range(n):
			arr[i] = int(arr[i])
		arr.sort()
		return arr[1] * arr[0]


class Solution:

	def printMinimumProduct(self, a, n):
		a.sort(key=lambda x: int(x))
		return int(a[0]) * int(a[1])


class Solution:

	def printMinimumProduct(self, arr, n):
		arr = [int(val) for val in arr]
		arr.sort()
		return arr[0] * arr[1]


class Solution:

	def printMinimumProduct(self, a, n):
		min1 = 10000000
		min2 = 10000000
		for i in range(n):
			if min1 >= int(a[i]):
				min2 = min1
				min1 = int(a[i])
			elif min2 >= int(a[i]):
				min2 = int(a[i])
		return min1 * min2


class Solution:

	def printMinimumProduct(self, a: list, n: int) -> int:
		x = self.findMinIndex([int(num) for num in a])
		y = self.findMinIndex([int(num) for num in a], x)
		return int(a[x]) * int(a[y])

	@staticmethod
	def findMinIndex(arr: list, first_min=None) -> int:
		(min_index, min_value) = (None, float('inf'))
		for (index, value) in enumerate(arr):
			if index == first_min:
				continue
			elif value < min_value:
				(min_index, min_value) = (index, value)
		return min_index


class Solution:

	def printMinimumProduct(self, a, n):
		a = list(map(int, a))
		a.sort()
		x = a[0]
		y = a[1]
		return x * y


class Solution:

	def printMinimumProduct(self, a, n):
		first = float('inf')
		second = float('inf')
		for i in a:
			if int(i) < first:
				second = first
				first = int(i)
			elif int(i) < second:
				second = int(i)
		return first * second


class Solution:

	def printMinimumProduct(self, a, n):
		min1 = float('inf')
		min2 = float('inf')
		for elem in a:
			num = int(elem)
			if num < min1:
				min2 = min1
				min1 = num
			elif num < min2:
				min2 = num
		return min1 * min2


from collections import Counter

class Solution:

	def printMinimumProduct(self, a, n):
		a = list(map(int, a))
		a.sort()
		return int(a[0]) * int(a[1])


class Solution:

	def printMinimumProduct(self, a, n):
		k = []
		for i in a:
			k.append(int(i))
		p = sorted(k)
		return p[0] * p[1]


class Solution:

	def printMinimumProduct(self, a, n):
		b = []
		for i in range(n):
			b.append(int(a[i]))
		b.sort()
		return int(b[0]) * int(b[1])


class Solution:

	def printMinimumProduct(self, a, n):
		minA = 999999
		minB = 999999
		for i in range(0, n):
			num = int(a[i])
			if minA > num:
				temp = minA
				minA = min(minA, num)
				minB = temp
			elif minB > num:
				minB = min(minB, num)
		return minA * minB


class Solution:

	def printMinimumProduct(self, a, n):
		first = 123345567
		second = 12345678
		a = list(map(int, a))
		for i in range(n):
			if a[i] < first:
				second = first
				first = a[i]
			elif a[i] < second:
				second = a[i]
		return first * second


class Solution:

	def printMinimumProduct(self, a, n):
		a = [int(x) for x in a]
		m1 = max(a)
		m2 = max(a)
		for x in range(n):
			if a[x] < m1:
				m2 = m1
				m1 = a[x]
			elif a[x] < m2:
				m2 = a[x]
		return int(m1) * int(m2)


class Solution:

	def printMinimumProduct(self, a, n):
		a.sort(key=int)
		mul = int(a[0]) * int(a[1])
		return mul

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [x for x in input().strip().split()]
		print(Solution().printMinimumProduct(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def printMinimumProduct(self, a, n):
		a = [int(i) for i in a]
		if n == 2:
			return a[0] * a[1]
		min_a = min(a[0], a[1])
		max_a = max(a[0], a[1])
		for i in range(2, n):
			if a[i] < min_a:
				max_a = min_a
				min_a = a[i]
			elif a[i] < max_a:
				max_a = a[i]
		return min_a * max_a

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [x for x in input().strip().split()]
		print(Solution().printMinimumProduct(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def printMinimumProduct(self, a, n):
		a = list(map(lambda x: int(x), a))
		a.sort()
		return a[0] * a[1]

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [x for x in input().strip().split()]
		print(Solution().printMinimumProduct(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def printMinimumProduct(self, arr, n):
		mi = 999999999
		for i in range(n):
			arr[i] = int(arr[i])
			if arr[i] < mi:
				mi = arr[i]
				m = i
		arr[m] = 9999999
		n = min(arr)
		return mi * n

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [x for x in input().strip().split()]
		print(Solution().printMinimumProduct(a, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def printMinimumProduct(self, a, n):
		if len(a) == 1:
			return a[0]
		elif int(a[0]) > int(a[1]):
			s = a[1]
			sl = a[0]
		else:
			s = a[0]
			sl = a[1]
		for i in range(2, len(a)):
			if int(a[i]) < int(sl):
				sl = a[i]
			if int(a[i]) < int(s):
				sl = s
				s = a[i]
		return int(s) * int(sl)


class Solution:

	def printMinimumProduct(self, arr, n):
		first_min = min(int(arr[0]), int(arr[1]))
		second_min = max(int(arr[0]), int(arr[1]))
		for i in range(2, n):
			if int(arr[i]) < first_min:
				second_min = first_min
				first_min = int(arr[i])
			elif int(arr[i]) < second_min:
				second_min = int(arr[i])
		return int(first_min) * int(second_min)


class Solution:

	def printMinimumProduct(self, a, n):
		a = [int(x) for x in a]
		mi1 = 99999999
		mi2 = 99999999
		for i in range(n):
			mi1 = min(mi1, a[i])
		k = a.count(mi1)
		for i in range(n):
			if a[i] == mi1:
				continue
			mi2 = min(a[i], mi2)
		if k > 1:
			return mi1 * mi1
		return mi1 * mi2


class Solution:

	def printMinimumProduct(self, a, n):
		import sys
		firstMinNum = int(sys.maxsize)
		secondMinNum = int(sys.maxsize)
		for i in range(n):
			if int(a[i]) < firstMinNum:
				secondMinNum = firstMinNum
				firstMinNum = int(a[i])
			elif int(a[i]) >= firstMinNum and int(a[i]) < secondMinNum:
				secondMinNum = int(a[i])
		return firstMinNum * secondMinNum


class Solution:

	def printMinimumProduct(self, a, n):
		x = float('inf')
		y = float('inf')
		for i in a:
			if int(i) < x:
				y = x
				x = int(i)
			elif int(i) < y:
				y = int(i)
		return x * y


class Solution:

	def printMinimumProduct(self, a, n):
		a = [int(i) for i in a]
		prod = 1
		m = min(a)
		prod = prod * m
		a.remove(m)
		m1 = min(a)
		prod = prod * m1
		return prod


class Solution:

	def printMinimumProduct(self, a, n):
		mi1 = int(a[0])
		imi1 = 0
		for i in range(1, n):
			if int(a[i]) < mi1:
				mi1 = int(a[i])
				imi1 = i
		a[imi1] = 100000
		mi2 = int(a[0])
		for i in range(1, n):
			if int(a[i]) < mi2:
				mi2 = int(a[i])
		x = mi1 * mi2
		return x


import heapq

class Solution:

	def printMinimumProduct(self, a, n):
		a = [int(x) for x in a]
		heapq.heapify(a)
		return heapq.heappop(a) * heapq.heappop(a)


class Solution:

	def printMinimumProduct(self, a, n):
		for i in range(0, n):
			a[i] = int(a[i])
		min = 0
		max = 0
		for i in range(1, n):
			if a[i] < a[min]:
				min = i
			if a[i] > a[max]:
				max = i
		first = a[min]
		for j in range(0, n):
			if a[j] == a[min]:
				a[j] = a[max]
		minima = 0
		for i in range(1, n):
			if a[i] < a[minima]:
				minima = i
		second = a[minima]
		return first * second


class Solution:

	def printMinimumProduct(self, a, n):
		fm = 100000
		sm = 100000
		for i in a:
			if int(i) < fm:
				sm = fm
				fm = int(i)
			elif int(i) < sm and fm <= int(i):
				sm = int(i)
		return fm * sm


class Solution:

	def printMinimumProduct(self, a, n):
		cur_min = min(int(a[0]), int(a[1]))
		cur_second_min = max(int(a[0]), int(a[1]))
		for el in a[2:]:
			el = int(el)
			if el <= cur_min:
				cur_second_min = cur_min
				cur_min = el
			elif el < cur_second_min:
				cur_second_min = el
		ans = cur_second_min * cur_min
		return ans