Given two square matrices Grid1 and Grid2 with the same dimensions(NxN).Check whether they are identical or not.
Example 1:
Input:
N=2
Grid1=[[1,2],[3,4]]
Grid2=[[1,2],[3,4]]
Output:
1
Explanation:
Both the matrices are identical,
so the answer is 1.
Example 2:
Input:
N=2
Grid1=[[1,2][3,4]]
Grid2=[[1,2][3,2]]
Output:
0
Explanation:
Both the matrices are not identical,
So, answer is 0.
Your Task:
You don't need to read input or print anything.Your task is to complete the function areMatricesIdentical() which takes the integer N and two 2D arrays Grid1 and Grid2 as input parameters and returns 1 if the matrices are identical.Otherwise,it returns 0.
Expected Time Complexity:O(N^{2})
Expected Auxillary Space:O(1)
Constraints:
1<=N<=1000
-1000<=Grid1[i][j],Grid2[i][j]<=1000,for 0<=i,j

Source: geeksforgeeks | Difficulty: EASY
Tags: Matrices

Data structures

Starter code: #User function Template for python3

class Solution:
    def areMatricesidentical(self,N,Grid1,Grid2):
        #code here

Solutions:
class Solution:

	def areMatricesidentical(self, N, A, B):
		count = 1
		for i in range(N):
			for j in range(N):
				if A[i][j] == B[i][j]:
					pass
				else:
					count = 0
		return count


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		for i in range(N):
			for j in range(N):
				if Grid1[i][j] == Grid2[i][j]:
					pass
				else:
					return 0
		return 1


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		for i in range(len(Grid1)):
			cols1 = len(Grid1[i])
			cols2 = len(Grid2[i])
			if cols1 != cols2:
				return 0
			for j in range(cols1):
				if Grid1[i][j] != Grid2[i][j]:
					return 0
		return 1


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		for i in range(N):
			if Grid1[i] != Grid2[i]:
				return 0
		return 1


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		if Grid1 == Grid2:
			return 1
		return 0


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		flag = True
		for i in range(N):
			for j in range(N):
				if Grid1[i][j] != Grid2[i][j]:
					flag = False
		if flag == True:
			return 1
		else:
			return 0


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		sum1 = 0
		sum2 = 0
		for i in range(N):
			if Grid1[i] == Grid2[i]:
				continue
			else:
				return 0
		return 1


class Solution:

	def areMatricesidentical(self, N, a, b):
		for i in range(N):
			for j in range(N):
				if a[i][j] != b[i][j]:
					return 0
		return 1


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		c = 0
		for i in range(N):
			x = Grid1[i]
			y = Grid2[i]
			if x == y:
				c += 1
		if c == N:
			return 1
		else:
			return 0


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		nope = 0
		for i in range(N):
			for j in range(N):
				if Grid1[i][j] == Grid2[i][j]:
					continue
				else:
					nope = 1
					break
		if nope == 1:
			return 0
		else:
			return 1


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		l1 = []
		l2 = []
		for i in Grid1:
			for j in i:
				l1.append(j)
		for i in Grid2:
			for j in i:
				l2.append(j)
		if l1 == l2:
			return 1
		else:
			return 0


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		l = []
		m = []
		for i in range(len(Grid1)):
			for j in range(len(Grid1[i])):
				l.append(Grid1[i][j])
				m.append(Grid2[i][j])
		if l == m:
			return 1
		else:
			return 0


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		size = N * N
		count = 0
		for i in range(N):
			for j in range(N):
				if Grid1[i][j] == Grid2[i][j]:
					count += 1
				else:
					continue
		if size == count:
			return 1
		else:
			return 0


class Solution:

	def areMatricesidentical(self, n, G1, G2):
		for i in range(n):
			for j in range(n):
				if G1[i][j] != G2[i][j]:
					return 0
		return 1


from itertools import chain

class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		if list(chain(*Grid1)) == list(chain(*Grid2)):
			return 1
		else:
			return 0


class Solution:

	def areMatricesidentical(self, N, Grid1, Grid2):
		return int(Grid1 == Grid2)


class Solution:

	def areMatricesidentical(self, N, g1, g2):
		return int(g1 == g2)