r1 is the top row , c1 is the left col r2 is the bottom row , c2 is the right
def hasSquareOfZeroes ( r1 , c1 , r2 , c2 ) : NEW_LINE INDENT global matrix , cache NEW_LINE if ( r1 >= r2 or c1 >= c2 ) : NEW_LINE INDENT return False NEW_LINE DEDENT key = ( str ( r1 ) + ' - ' + str ( c1 ) + ' - ' + str ( r2 ) + ' - ' + str ( c2 ) ) NEW_LINE if ( key in cache ) : NEW_LINE INDENT return cache [ key ] NEW_LINE DEDENT cache [ key ] = ( isSquareOfZeroes ( r1 , c1 , r2 , c2 ) or hasSquareOfZeroes ( r1 + 1 , c1 + 1 , r2 - 1 , c2 - 1 ) ) NEW_LINE cache [ key ] = ( cache [ key ] or hasSquareOfZeroes ( r1 , c1 + 1 , r2 - 1 , c2 ) or hasSquareOfZeroes ( r1 + 1 , c1 , r2 , c2 - 1 ) ) NEW_LINE cache [ key ] = ( cache [ key ] or hasSquareOfZeroes ( r1 + 1 , c1 + 1 , r2 , c2 ) or hasSquareOfZeroes ( r1 , c1 , r2 - 1 , c2 - 1 ) ) NEW_LINE return cache [ key ] NEW_LINE DEDENT