Question: Please do this in python. Debugging - Maximum Square Matrix with all Zeroes You have been given a problem which has a solution to it

Please do this in python.

Debugging - Maximum Square Matrix with all Zeroes

You have been given a problem which has a solution to it already. You need to find out the bug/bugs(if any)

Given a n*m matrix which contains only 0s and 1s, find out the size of maximum square sub-matrix with all 0s. You need to return the size of square with all 0s.

Input format : Line 1 : n and m (space separated positive integers) Next n lines : m elements of each row (separated by space).

Constraints: The maximum value of n and m can be 1000.

Output Format: Line 1 : Size of maximum square sub-matrix

Sample Input : 3 3 1 1 0 1 1 1 1 1 1

Sample Output : 1

CODE:

def findMaxSquareWithAllZeros(arr): row = len(arr) col = len(arr[0])

storage = [[0 for i in range(col+1)] for j in range(row+1)]

for i in range(row,-1,-1): for j in range(col,-1,-1): storage[i][j] = min(storage[i+1][j], storage[i][j+1]) maximum = storage[i][j]

if max(row-i, col-j)

foundOne = True

for p in range(0, maximum+1): for q in range(0, maximum+1): if arr[i+p][j+q]==1: foundOne = True break if foundOne: break

if foundOne==False: storage[i][j] += 1

return storage[i][j]

This is how code looks in editor:

Please do this in python. Debugging - Maximum Square Matrix with all

12 16 1 ## Read input as specified in the question. 2 ## Print output as specified in the question. 3 def findMaxSquare WithAllZeros(arr): 5 row = len(arr) 6 col = len(arr[0]) 7 8 storage = [[O for i in range(col+1)] for jin range(row+1)] 9 10 for i in range(row,-1,-1): 11 for j in range(col,-1,-1): storage[i][j] = min(storage[i+1][j], storage[i][j+1]) 13 maximum = storage[i] [] 14 15 if max(row-i, col-j)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!