look above
if ( i > 0 && abs ( mat [ i - 1 ] [ j ] - mat [ i ] [ j ] ) == 1 ) { lookup [ i ] [ j ] = max ( lookup [ i ] [ j ] , lookup [ i - 1 ] [ j ] + 1 ) ; if ( max_len < lookup [ i ] [ j ] ) { max_len = lookup [ i ] [ j ] ; max_row = i , max_col = j ; } }