Count saddle point

Viewed 33

Really appreciate to hear feedback on a coding challenge. I would like to hear suggestions as to why my output generate 41 where the Judge says 663?

Count "saddle" value in a matrix. ** A value is considered as "saddle" when it is largest in the row and smallest in the column. **

Input Format

First line contains M and N that are the number of rows and columns in matrix (M,N ≤100). The next M lines, each line is N non-negative integers a[i][j] (a[i][j] <= 1000 with 0≤i<M,0≤j<N). Rows are marked from 0 to M-1, and columns are from 0 to N-1.

Output Format ##:

The number of "saddle" values

m , n = list(map(int, input().split()))
a = []
for i in range(m):
    a.append(list(map(int,input().split())))    

# Declare the name of the maximum
count = 0
for i in range(m):
    for j in range(n):
        maximum = 0
        minimum = 10**9
        if (a[i][j] == max(a[i])):
            maximum = a[i][j]  
            for k in range(m): 
                if (minimum > a[k][j]):
                    minimum = a[k][j]
                    if (k == i):
                        count += 1
print(count)

Input:

25 39

1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 100... After running, the code complied and returned a different output from answer:

Output 41

Answer 663

Did I miss anything? Thank you for clarifying!

0 Answers
Related