Run
def find(mat, N, M):
for j in range(0, N):
x, count = mat[0][j], 0
for i in range(1, M):
flag = 0
for k in range(0, N):
if x == mat[i][k]:
flag = 1
mat[i][k] = -1
break
if flag == 1:
count += 1
if count == M - 1:
print(x)
N, M = 4, 4
mat = [[10, 20, 30, 40],
[15, 25, 35, 30],
[27, 30, 37, 48],
[32, 33, 39, 30]]
find(mat, N, M)
def sort(arr):
l=[]
for i in range(len(arr)):
k=arr[0][i]
for j in range(1,len(arr)):
if k in arr[j]:
continue
else:
break
else:
l.append(k)
print(l)
mat = [[10, 20, 30, 40],
[15, 25, 35, 30],
[27, 30, 37, 48],
[32, 33, 39, 30]]
sort(mat)
r=int(input())
c=int(input())
matrix=[]
sort_mat=[]
# taking inputs in matrix
for _ in range(r):
row=[]
for _ in range(c):
row.append(int(input()))
matrix.append(row)
# print(matrix)
# changing matrix into a single array (flatten)
for i in range(r):
for j in range(c):
sort_mat.append(matrix[i][j])
# print(sort_mat)
# count the maximum times a number is repeated
max_count=0
for i in sort_mat:
count=sort_mat.count(i)
if count>max_count:
max_count=count
store=i
print(i,max_count)