Now check , for every value of ( i , j ) if sub - square is possible , traverse back horizontally by value val , and check if vertical contiguous ' X ' enfing at ( i , j - val + 1 ) is greater than equal to val . Similarly , check if traversing back vertically , the horizontal contiguous ' X ' ending at ( i - val + 1 , j ) is greater than equal to val .
int maxval = 0 , val = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { val = min ( dp [ i ] [ j ] . first , dp [ i ] [ j ] . second ) ; if ( dp [ i ] [ j - val + 1 ] . second >= val && dp [ i - val + 1 ] [ j ] . first >= val ) maxside [ i ] [ j ] = val ; else maxside [ i ] [ j ] = 0 ;