Symmetric Matrix @ Dcoder

Words
46
Reading
1 min
3y
Listen to this post
~1 min

Problem: Given a matrix of dimensions N x N.
Print "YES"(without quotes) if it is a symmetric matrix, else print "NO"(without quotes).

Input: First line contains N.
Each of following N lines contains N integers each, denoting the matrix.

Output: Print the required answer.
Constraints: 1 <= N <= 100
1 <= matrix_element <= 100
Sample Input: 3
1 0 0
0 2 1
0 1 1

Sample Output:
YES

n = int( input() )
matrix = []
for i in range( n ):
    matrix.append( input().split() )
  
for i in range( 1, n - 1 ):
    for j in range( i, n ):
        if matrix[i][j] != matrix[j][i]:
            print( "NO" )
            break
    else:
        continue
    
    break
else:
    print( "YES" )