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 .
maxval = 0 NEW_LINE val = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT val = min ( dp [ i ] [ j ] [ 0 ] , dp [ i ] [ j ] [ 1 ] ) NEW_LINE if ( dp [ i ] [ j - val + 1 ] [ 1 ] >= val and dp [ i - val + 1 ] [ j ] [ 0 ] >= val ) : NEW_LINE INDENT maxside [ i ] [ j ] = val NEW_LINE DEDENT else : NEW_LINE INDENT maxside [ i ] [ j ] = 0 NEW_LINE DEDENT DEDENT DEDENT