Given an array A[] of size n. The task is to find the largest element in it.
 
Example 1:
Input:
n = 5
A[] = {1, 8, 7, 56, 90}
Output:
90
Explanation:
The largest element of given array is 90.
 
Example 2:
Input:
n = 7
A[] = {1, 2, 0, 3, 2, 4, 5}
Output:
5
Explanation:
The largest element of given array is 5.
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function largest() which takes the array A[] and its size n as inputs and returns the maximum element in the array.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= n<= 10^{3}
0 <= A[i] <= 10^{3}
Array may contain duplicate elements.

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



def largest( arr, n):

    





Solutions:
def largest(arr, n):
	high = arr[0]
	for i in range(1, n):
		if arr[i] >= high:
			high = arr[i]
	return high


def largest(arr, n):
	lar = arr[0]
	for x in arr:
		if x > lar:
			lar = x
	return lar


def largest(arr, n):
	max = arr[0]
	for i in range(0, n):
		if arr[i] > max:
			max = arr[i]
	return max


def largest(arr, n):
	return max(arr)


def largest(arr, n):
	largest = -9999
	for element in arr:
		if element > largest:
			largest = element
	return largest


def largest(arr, n):
	max1 = arr[0]
	for i in range(n):
		if max1 < arr[i]:
			max1 = arr[i]
	return max1


def largest(arr, n):
	arr.sort()
	return arr[n - 1]


def largest(arr, n):
	maximum = arr[0]
	for i in range(n):
		if arr[i] > maximum:
			maximum = arr[i]
	return maximum


def largest(arr, n):
	max = arr[0]
	for num in arr:
		if num > max:
			max = num
	return max


def largest(arr, n):
	max = -float('infinity')
	for num in arr:
		if num > max:
			max = num
	return max


def largest(arr, n):
	largest_element = arr[0]
	for i in arr:
		if i > largest_element:
			largest_element = i
	return largest_element


def largest(arr, n):
	t = -1
	for i in arr:
		if t < i:
			t = i
	return t


def largest(arr, n):
	m = float('-inf')
	for i in arr:
		if i > m:
			m = i
	return m


def largest(arr, n):
	maxn = float('-inf')
	for e in arr:
		if e > maxn:
			maxn = e
	return maxn


def largest(arr, n):
	max = -1
	for i in range(n):
		if arr[i] > max:
			max = arr[i]
	return max


def largest(arr, n):
	max = arr[0]
	for x in arr:
		if max < x:
			max = x
	return max


def largest(arr, n):
	maxi = -1000000000.0
	for i in arr:
		maxi = max(maxi, i)
	return maxi


def largest(arr, n):
	largest = arr[0]
	for i in range(len(arr)):
		if arr[i] > largest:
			largest = arr[i]
	return largest


def largest(arr, n):
	lar = 0
	for i in arr:
		if lar < i:
			lar = i
		else:
			continue
	return lar


def largest(arr, n):
	maxi = arr[0]
	for i in range(n):
		if arr[i] > maxi:
			maxi = arr[i]
	return maxi


def largest(arr, n):
	arr.sort(reverse=True)
	return arr[0]


def largest(arr, n):
	large_ele = arr[0]
	for idx in range(0, n):
		if arr[idx] > large_ele:
			large_ele = arr[idx]
	return large_ele


def largest(arr, n):
	Max = -1
	for i in arr:
		if i > Max:
			Max = i
	return Max


def largest(arr, n):
	max = arr[0]
	for x in range(0, len(arr)):
		if arr[x] > max:
			max = arr[x]
	return max


def largest(arr, n):
	grst = arr[0]
	for element in arr:
		if element > grst:
			grst = element
	return grst


def largest(arr, n):
	largest = arr[0]
	for ele in arr:
		if ele > largest:
			largest = ele
	return largest


def largest(arr, n):
	maxVal = float('-inf')
	for num in arr:
		maxVal = max(num, maxVal)
	return maxVal


def largest(arr, n):
	large = -999
	for i in arr:
		if i >= large:
			large = i
	return large


def largest(arr, n):
	if not arr:
		return None
	if len(arr) == 1:
		return arr[0]
	result = arr[0]
	for num in arr[1:]:
		if num > result:
			result = num
	return result


def largest(arr, n):
	m = -1
	for i in arr:
		if m < i:
			m = i
	return m


def largest(arr, n):
	maxi = arr[0]
	for i in range(1, n):
		maxi = max(maxi, arr[i])
	return maxi


def largest(arr, n):
	maxi = -1
	for ele in arr:
		if maxi < ele:
			maxi = ele
	return maxi


def largest(arr, n):
	max_ = 0
	for i in arr:
		max_ = max(i, max_)
	return max_


def largest(arr, n):
	maxs = 0
	for x in arr:
		if maxs < x:
			maxs = x
	return maxs


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


def largest(arr, n):
	arr.sort()
	arr = arr[::-1]
	if n == 0:
		return -1
	return arr[0]


def largest(arr, n):
	large = arr[0]
	for i in arr:
		if i > large:
			large = i
	return large


def largest(arr, n):
	p = 0
	for i in range(0, n):
		if p < arr[i]:
			p = arr[i]
	return p


def largest(arr, n):
	largest = -9999
	for i in range(len(arr)):
		if arr[i] > largest:
			largest = arr[i]
	return largest


def largest(arr, n):
	ans = -1
	for i in arr:
		ans = max(i, ans)
	return ans


def largest(arr, n):
	temp = -99999999999999
	for i in arr:
		if temp < i:
			temp = i
	return temp


def largest(arr, n):
	if len(arr) == 0:
		return -1
	max = arr[0]
	index = 0
	for i in range(len(arr)):
		if max < arr[i]:
			max = arr[i]
			index = i
	return max


def largest(arr, n):
	mx = 0
	for i in arr:
		if i > mx:
			mx = i
	return mx


def largest(arr, n):
	L = -1
	for k in arr:
		if k > L:
			L = k
	return L


def largest(arr, n):
	l = arr.sort()
	return max(arr)


def largest(arr, n):
	a = 0
	l = list(arr)
	for i in range(len(l)):
		if l[i] > a:
			a = l[i]
	return a


def largest(arr, n):
	for i in range(1, n):
		while arr[i] < arr[i - 1] and i != 0:
			(arr[i - 1], arr[i]) = (arr[i], arr[i - 1])
			i -= 1
	return arr[n - 1]


def largest(arr, n):
	for i in range(n):
		arr.sort()
		return arr[-1]