r1 is the top row , c1 is the left col r2 is the bottom row , c2 is the right
static boolean hasSquareOfZeroes ( int [ ] [ ] matrix , int r1 , int c1 , int r2 , int c2 , Map < String , Boolean > cache ) { if ( r1 >= r2 c1 >= c2 ) return false ; String key = r1 + " - " + c1 + " - " + r2 + " - " + c2 ; if ( cache . containsKey ( key ) ) return cache . get ( key ) ; cache . put ( 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 . get ( key ) ; }