Given a 2D (2 dimensional) array, find the largest element in it.
Write a function solution that accepts a 2D-array A and two integers M (number of rows) and N (number of columns). The function should return the largest element in an array.
Input
2
3
1 4 5
2 3 0
Output
5
M = int(input())
N = int(input())
A = []
for i in range(M):
row = [int(j) for j in input().split()]
if len(row) != N:
raise ValueError('Length of row is not N')
A.append(row)
largest = A[0][0]
for i in range(M):
for j in range(N):
if A[i][j] > largest:
largest = A[i][j]
print(largest)
Comments
Leave a comment