Given an array A of size N of integers. Your task is to find the minimum and maximum elements in the array.
 
Example 1:
Input:
N = 6
A[] = {3, 2, 1, 56, 10000, 167}
Output:
min = 1, max =  10000
 
Example 2:
Input:
N = 5
A[]  = {1, 345, 234, 21, 56789}
Output:
min = 1, max = 56789
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function getMinMax() which takes the array A[] and its size N as inputs and returns the minimum and maximum element of the array.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{5}
1 <= A_{i} <=10^{12}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



def getMinMax( a, n):

    

    

    

Solutions:
def getMinMax(a, n):
	return (min(a), max(a))


def getMinMax(a, n):
	min = a[0]
	max = 0
	for i in range(len(a)):
		if a[i] > max:
			max = a[i]
		if a[i] < min:
			min = a[i]
	return (min, max)


def getMinMax(a, n):
	min = a[0]
	max = a[0]
	for xx in range(n):
		if a[xx] > max:
			max = a[xx]
		if a[xx] < min:
			min = a[xx]
	return (min, max)


def getMinMax(a, n):
	for i in range(n):
		return (min(a), max(a))


def getMinMax(a, n):
	product = []
	product.append(min(a))
	product.append(max(a))
	return product


def getMinMax(a, n):
	min_ = min(a)
	max_ = max(a)
	return (min_, max_)


def getMinMax(a, n):
	mi = a[0]
	ma = a[0]
	for elt in a:
		if mi > elt:
			mi = elt
		if ma < elt:
			ma = elt
	return (mi, ma)


def getMinMax(a, n):
	mi = min(a)
	ma = max(a)
	return (mi, ma)


def getMinMax(a, n):
	A = max(a)
	M = min(a)
	return (M, A)


def getMinMax(a, n):
	a.sort()
	return (a[0], a[-1])


def getMinMax(a, n):
	minimum = maximum = a[0]
	for i in range(1, n):
		if a[i] < minimum:
			minimum = a[i]
		elif a[i] > maximum:
			maximum = a[i]
	return (minimum, maximum)


def getMinMax(a, n):
	lst = []
	lst.append(min(a))
	lst.append(max(a))
	return lst


def getMinMax(a, n):
	minNum = maxNum = a[0]
	for i in a:
		if i > maxNum:
			maxNum = i
		if i < minNum:
			minNum = i
	return [minNum, maxNum]


def getMinMax(a, n):
	if len(a) == 0:
		return (none, none)
	min_value = a[0]
	max_value = a[0]
	for i in a:
		if i < min_value:
			min_value = i
		if i > max_value:
			max_value = i
	return (min_value, max_value)


def getMinMax(a, n):
	for i in range(n):
		mi = min(a)
		ma = max(a)
		return (mi, ma)


def getMinMax(a, n):
	minn = 10 ** 12
	maxx = 0
	for i in a:
		minn = min(minn, i)
		maxx = max(i, maxx)
	a = []
	a.append(minn)
	a.append(maxx)
	return a


def getMinMax(a, n):
	if n == 1:
		return [a[0], a[0]]
	min = a[0]
	max = a[0]
	for i in range(n):
		if a[i] < min:
			min = a[i]
		elif a[i] > max:
			max = a[i]
	return [min, max]


def getMinMax(a, n):
	Min = a[0]
	Max = a[0]
	for i in range(n):
		if a[i] < Min:
			Min = a[i]
	for i in range(n):
		if a[i] > Max:
			Max = a[i]
	return (Min, Max)


def getMinMax(a, n):
	pos = a[0]
	neg = a[0]
	for i in a:
		if i > pos:
			pos = i
		if i < neg:
			neg = i
	return (neg, pos)


def getMinMax(a, n):
	min_i = max_i = a[0]
	for i in range(1, n):
		if max_i < a[i]:
			max_i = a[i]
		if min_i > a[i]:
			min_i = a[i]
	return (min_i, max_i)


def getMinMax(a, n):
	res = a[0]
	for i in range(1, n):
		res = min(res, a[i])
	res1 = a[0]
	for i in range(1, n):
		res1 = max(res1, a[i])
	return (res, res1)


def getMinMax(a, n):
	max_1 = a[0]
	min_1 = a[0]
	for i in range(1, n):
		if max_1 <= a[i]:
			max_1 = a[i]
		if min_1 >= a[i]:
			min_1 = a[i]
	return (min_1, max_1)


def getMinMax(a, n):
	mina = a[0]
	maxa = a[0]
	for i in a:
		mina = min(i, mina)
		maxa = max(i, maxa)
	return (mina, maxa)


def getMinMax(a, n):
	x = []
	x.append(min(a))
	x.append(max(a))
	return x


def getMinMax(arr, n):
	if n % 2 == 0:
		mx = max(arr[0], arr[1])
		mn = min(arr[0], arr[1])
		i = 2
	else:
		mx = mn = arr[0]
		i = 1
	while i < n - 1:
		if arr[i] < arr[i + 1]:
			mx = max(mx, arr[i + 1])
			mn = min(mn, arr[i])
		else:
			mx = max(mx, arr[i])
			mn = min(mn, arr[i + 1])
		i += 2
	return (mn, mx)


def getMinMax(a, n):
	min_ = a[0]
	max_ = 0
	for i in a:
		if max_ < i:
			max_ = i
		elif min_ > i:
			min_ = i
	return [min_, max_]


def getMinMax(a, n):
	max_value = a[0]
	min_value = a[0]
	for i in range(1, n):
		if min_value > a[i]:
			min_value = a[i]
	for j in range(1, n):
		if max_value < a[j]:
			max_value = a[j]
	return (min_value, max_value)


def getMinMax(a, n):
	arr = sorted(a)
	return (arr[0], arr[n - 1])


def getMinMax(a, n):
	sortedArr = []
	smallest = a[0]
	largest = 0
	for i in range(0, n):
		if smallest > a[i]:
			smallest = a[i]
		elif largest < a[i]:
			largest = a[i]
	return [smallest, largest]


import sys

def getMinMax(a, n):
	maxi = 0
	mini = sys.maxsize
	for i in a:
		if maxi < i:
			maxi = i
		if mini > i:
			mini = i
	lis = []
	lis.append(mini)
	lis.append(maxi)
	return lis


def getMinMax(a, n):
	mi = a[0]
	mx = a[0]
	for i in range(1, n):
		if a[i] > mx:
			mx = a[i]
		if a[i] < mi:
			mi = a[i]
	return (mi, mx)


def getMinMax(a, n):
	min1 = a[0]
	max2 = a[0]
	for i in range(n):
		min1 = min(min1, a[i])
		max2 = max(max2, a[i])
	return (min1, max2)


def getMinMax(a, n):
	l = []
	res = min(a)
	res1 = max(a)
	l.append(res)
	l.append(res1)
	return l


def getMinMax(a, n):
	if n == 1:
		return 0
	arr = a
	(min_num, max_num) = (arr[0], arr[1])
	for i in range(n):
		if arr[i] > max_num:
			max_num = arr[i]
		if arr[i] < min_num:
			min_num = arr[i]
	return (min_num, max_num)


def getMinMax(a, n):
	l = []
	s1 = min(a)
	s2 = max(a)
	l.append(s1)
	l.append(s2)
	return l


import sys

def getMinMax(a, n):
	res = []
	maxi = sys.maxsize
	mini = -sys.maxsize - 1
	for i in range(0, n):
		if a[i] > mini:
			mini = a[i]
		if a[i] < maxi:
			maxi = a[i]
	return (maxi, mini)


def getMinMax(a, n):
	min_a = min(a)
	max_a = max(a)
	return (min_a, max_a)


def getMinMax(a, n):
	mini = a[0]
	maxi = a[0]
	for i in range(len(a)):
		if a[i] > maxi:
			maxi = a[i]
		elif a[i] < mini:
			mini = a[i]
	return [mini, maxi]


def getMinMax(a, y):
	x = min(a)
	y = max(a)
	return (x, y)


def getMinMax(a, n):
	min_val = max_val = a[0]
	for i in range(1, n):
		if a[i] < min_val:
			min_val = a[i]
		elif a[i] > max_val:
			max_val = a[i]
	return (min_val, max_val)


def getMinMax(A, N):
	min_element = float('inf')
	max_element = float('-inf')
	for i in range(N):
		if A[i] < min_element:
			min_element = A[i]
		if A[i] > max_element:
			max_element = A[i]
	return (min_element, max_element)


def getMinMax(a, n):
	min_element = a[0]
	max_element = a[0]
	for i in range(1, n):
		if a[i] < min_element:
			min_element = a[i]
		elif a[i] > max_element:
			max_element = a[i]
	return (min_element, max_element)