Minimum reduce operations to convert a given string into a palindrome | CPP program to count minimum reduce operations to make a palindrome ; Returns count of minimum character reduce operations to make palindrome . ; Compare every character of first half with the corresponding character of second half and add difference to result . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countReduce ( string & str ) { int n = str . length ( ) ; int res = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) res += abs ( str [ i ] - str [ n - i - 1 ] ) ; return res ; } int main ( ) { string str = " abcd " ; cout << countReduce ( str ) ; return 0 ; }