My code with time complexity O(M*N) gives TLE. But,the editorial code in python is almost same and has same time complexity

class Solution:
# @param A : list of list of integers
# @return the same list modified
def setZeroes(self, A):
l_r = []
l_c = []
for row in range(len(A)):
for col in range(len(A[0])):
if A[row][col] == 0:
l_r.append(row)
l_c.append(col)
for row in range(len(A)):
for col in range(len(A[0])):
if row in l_r:
A[row][col] = 0
elif col in l_c:
A[row][col] = 0
return A

Click here to start solving coding interview questions