Replace even | Function to count the minimum number of substrings of str1 such that replacing even - indexed characters of those substrings converts the string 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
function min_Operations ( str1 , str2 ) { var N = str1 . length ; var cntOp = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( str1 . charCodeAt ( i ) == str2 . charCodeAt ( i ) ) { continue ; } var ptr = i ; while ( ptr < N && str1 [ ptr ] != str2 [ ptr ] ) { str1 = str1 . substring ( 0 , ptr ) + str2 [ ptr ] + str1 . substring ( ptr + 1 ) ; ptr += 2 ; } cntOp ++ ; } return cntOp ; } str1 = " " ; str2 = " " ; document . write ( min_Operations ( str1 , str2 ) ) ;