Answer to Question #289226 in Python for sai krishna

Question #289226

you are given an 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:

4

1 2 3 4

2 3 4 1

3 4 1 2

4 1 2 3

OUTPUT- True.

INPUT:

4

1 2 3 3

2 3 4 1

3 4 1 2

4 1 2 3

OUTPUT- False


1
Expert's answer
2022-01-23T15:21:19-0500
def calculate_unique(matr, size):


	ells = [i+1 for i in range(size)]
	for i in range(size):
		row = matr[i]
		col = [matr[j][i] for j in range(size)]
		for el in ells:
			if (el not in row) or (el not in col):
				return False


	return True


n = int(input("n: "))
while n < 0:


	n = int(input("n: "))




M = []
for i in range(n):
	row = [int(i) for i in input(f"{i+1} line\n").split()]
	while len(row) != n:
		row = [int(i) for i in input(f"{i+1} line\n").split()]
	M.append(row)


print(calculate_unique(M, n))

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