Function to find the maximum distance
def maxDistance ( grid ) : NEW_LINE INDENT if ( len ( grid ) == 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT N = len ( grid ) NEW_LINE INF = 1000000 NEW_LINE if grid [ 0 ] [ 0 ] == 1 : NEW_LINE INDENT grid [ 0 ] [ 0 ] = 0 NEW_LINE DEDENT else : NEW_LINE INDENT grid [ 0 ] [ 0 ] = INF NEW_LINE DEDENT DEDENT