Minimum substring flips required to convert a Binary String to another | Function to count the minimum number of reversals required to make the given binary strings s1 and s2 same ; Stores the minimum count of reversal of substrings required ; If the length of the strings are not the same then return - 1 ; Iterate over each character ; If s1 [ i ] is not equal to s2 [ i ] ; Iterate until s1 [ i ] != s2 [ i ] ; Increment answer by 1 ; Return the resultant count of reversal of subrequired ; Driver Code ; Function Call
def canMakeSame ( s1 , s2 ) : NEW_LINE INDENT ans = - 1 NEW_LINE if ( len ( s1 ) != len ( s2 ) ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT N = len ( s1 ) NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT if ( s1 [ i ] != s2 [ i ] ) : NEW_LINE INDENT while ( i < len ( s1 ) and s1 [ i ] != s2 [ i ] ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT ans += 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT S1 = "100001" NEW_LINE S2 = "110111" NEW_LINE print ( canMakeSame ( S1 , S2 ) ) NEW_LINE