Minimize flips required to make all shortest paths from top | Function to count the minimum number of flips required ; Dimensions of matrix ; Stores the count the flips ; Check if element is same or not ; Return the final count ; Given Matrix ; Given path as a string ; Function call
def minFlips ( mat , s ) : NEW_LINE INDENT N = len ( mat ) NEW_LINE M = len ( mat [ 0 ] ) NEW_LINE count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if ( mat [ i ] [ j ] != ord ( s [ i + j ] ) - ord ( '0' ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT mat = [ [ 1 , 0 , 1 ] , [ 0 , 1 , 1 ] , [ 0 , 0 , 0 ] ] NEW_LINE s = "10001" NEW_LINE print ( minFlips ( mat , s ) ) NEW_LINE