Replace even | Function to count the minimum number of substrings of str1 such that replacing even - indexed characters of those substrings converts the str1 to str2 ; Stores length of str1 ; Stores minimum count of operations to convert str1 to str2 ; Traverse both the given string ; If current character in both the strings are equal ; Stores current index of the string ; If current character in both the strings are not equal ; Replace str1 [ ptr ] by str2 [ ptr ] ; Update ptr ; Update cntOp ; Driver Code
def minOperationsReq ( str11 , str22 ) : NEW_LINE INDENT str1 = list ( str11 ) NEW_LINE str2 = list ( str22 ) NEW_LINE N = len ( str1 ) NEW_LINE cntOp = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( str1 [ i ] == str2 [ i ] ) : NEW_LINE INDENT continue NEW_LINE DEDENT ptr = i NEW_LINE while ( ptr < N and str1 [ ptr ] != str2 [ ptr ] ) : NEW_LINE INDENT str1 [ ptr ] = str2 [ ptr ] NEW_LINE ptr += 2 NEW_LINE DEDENT cntOp += 1 NEW_LINE DEDENT return cntOp NEW_LINE DEDENT str1 = " abcdef " NEW_LINE str2 = " ffffff " NEW_LINE print ( minOperationsReq ( str1 , str2 ) ) NEW_LINE