Check if a matrix can be converted to another by repeatedly adding any value to X consecutive elements in a row or column | Function to check whether Matrix A [ ] [ ] can be transformed to Matrix B [ ] [ ] or not ; Traverse the matrix to perform horizontal operations ; Calculate difference ; Update next X elements ; Traverse the matrix to perform vertical operations ; Calculate difference ; Update next K elements ; A [ i ] [ j ] is not equal to B [ i ] [ j ] ; Conversion is not possible ; Conversion is possible ; Driver Code ; Input
def Check ( A , B , M , N , X ) : NEW_LINE INDENT for i in range ( M ) : NEW_LINE INDENT for j in range ( N - X + 1 ) : NEW_LINE INDENT if ( A [ i ] [ j ] != B [ i ] [ j ] ) : NEW_LINE INDENT diff = B [ i ] [ j ] - A [ i ] [ j ] NEW_LINE for k in range ( X ) : NEW_LINE INDENT A [ i ] [ j + k ] = A [ i ] [ j + k ] + diff NEW_LINE DEDENT DEDENT DEDENT DEDENT for i in range ( M - X + 1 ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT if ( A [ i ] [ j ] != B [ i ] [ j ] ) : NEW_LINE INDENT diff = B [ i ] [ j ] - A [ i ] [ j ] NEW_LINE for k in range ( X ) : NEW_LINE INDENT A [ i + k ] [ j ] = A [ i + k ] [ j ] + diff NEW_LINE DEDENT DEDENT DEDENT DEDENT for i in range ( M ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT if ( A [ i ] [ j ] != B [ i ] [ j ] ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT DEDENT return 1 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT M , N , X = 2 , 2 , 2 NEW_LINE A = [ [ 0 , 0 ] , [ 0 , 0 ] ] NEW_LINE B = [ [ 1 , 2 ] , [ 0 , 1 ] ] NEW_LINE if ( Check ( A , B , M , N , X ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT