r1 is the top row , c1 is the left col r2 is the bottom row , c2 is the right
static bool hasSquareOfZeroes ( int [ , ] matrix , int r1 , int c1 , int r2 , int c2 , Dictionary < string , bool > cache ) { if ( r1 >= r2 c1 >= c2 ) { return false ; } string key = r1 + " - " + c1 + " - " + r2 + " - " + c2 ; if ( cache . ContainsKey ( key ) ) { return cache [ key ] ; } cache [ key ] = ( isSquareOfZeroes ( matrix , r1 , c1 , r2 , c2 ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 - 1 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 + 1 , r2 - 1 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 , r2 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 , r2 - 1 , c2 - 1 , cache ) ) ; return cache [ key ] ; }