Answer to Question #311047 in Python for Manish

Question #311047

Unique Matrix

You are given a N*N matrix. write a program to check if the matrix is unique or not. A unique Matrix is a matrix if every row and column of the matrix contains all the integers from 1 to N


Input

The first line contains an integer N.

The next N lines contains N space separated values of the matrix.


Output:

The output contains a single line and should be True if the matrix is unique matrix and False otherwise.


Sample input:

4

1 2 3 4

2 3 4 1

3 4 1 2

4 1 2 3

Sample output:

True


Sample Input2

4

1 2 3 3

2 3 4 1

3 4 1 2

4 1 2 3

Sample Output

False


1
Expert's answer
2022-03-16T02:43:47-0400
matrix=[]
print('Enter N: ', end='')
n = int(input())
print('Enter matrix:')
for i in range(n):
    a = input().split()
    matrix.append([])    
    for j in range(n):
        matrix[i].append(int(a[j]))
for num in range(1, n+1):
    for k in range(n):
        check = 0
        for i in range(n):
            if num == matrix[k][i]:
                check = 1
        if check == 0:
            break
        check = 0
        for i in range(n):
            if num == matrix[i][k]:
                check = 1
        if check == 0:
            break
    if check == 0:
        break
if check == 1:
    print('True')
else:
    print('False')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS