human
Check if two elements of a matrix are on the same diagonal or not | Function to check if two integers are on the same diagonal of the matrix.
Storing Indexes of y in P , Q.
Condition to check if the both the elements are in same diagonal of a matrix.
Driver Code.
Dimensions of Matrix.
Given Matrix.
elements to be checked.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to check if two elements of a matrix are on the same diagonal or not and the other steps required.
 def checkSameDiag ( x , y ) :
	for i in range ( m ) :
		for j in range ( n ) :
			if li [ i ] [ j ] == x :
				I , J = i , j
			if li [ i ] [ j ] == y :
				P , Q = i , j
	if P - Q == I - J or P + Q == I + J :
		print ( " YES " )
	else :
		print ( " NO " )
if __name__ == " _ _ main _ _ " :
	m , n = 6 , 5
	li = [ [ 32 , 94 , 99 , 26 , 82 ] , [ 51 , 69 , 52 , 63 , 17 ] , [ 90 , 36 , 88 , 55 , 33 ] , [ 93 , 42 , 73 , 39 , 28 ] , [ 81 , 31 , 83 , 53 , 10 ] , [ 12 , 29 , 85 , 80 , 87 ] ]
	x , y = 42 , 80
	checkSameDiag ( x , y )