Minimize replacements or swapping of same indexed characters required to make two given strings palindromic | Function to find minimum operations to make both the strings palindromic ; Stores index of the left pointer ; Stores index of the right pointer ; Stores count of minimum operations to make both the strings palindromic ; if str1 [ i ] equal to str1 [ j ] and str2 [ i ] not equal to str2 [ j ] ; Update cntOp ; If str1 [ i ] not equal to str1 [ j ] and str2 [ i ] equal to str2 [ j ] ; Update cntOp ; If str1 [ i ] is not equal to str1 [ j ] and str2 [ i ] is not equal to str2 [ j ] ; If str1 [ i ] is equal to str2 [ j ] and str2 [ i ] is equal to str1 [ j ] ; Update cntOp ; Update cntOp ; Update i and j ; Driver Code ; Stores length of str1
function MincntBothPalin ( str1 , str2 , N ) { var i = 0 ; var j = N - 1 ; var cntOp = 0 ; while ( i < j ) { if ( str1 [ i ] === str1 [ j ] && str2 [ i ] !== str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] !== str1 [ j ] && str2 [ i ] === str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] !== str1 [ j ] && str2 [ i ] !== str2 [ j ] ) { if ( str1 [ i ] === str2 [ j ] && str2 [ i ] === str1 [ j ] ) { cntOp += 1 ; } else { cntOp += 2 ; } } i += 1 ; j -= 1 ; } return cntOp ; } var str1 = " " ; var str2 = " " ; var N = str1 . length ; document . write ( MincntBothPalin ( str1 , str2 , N ) ) ;