Minimum removal to make palindrome permutation | CPP Program to find minimum number of removal to make any permutation of the string a palindrome ; function to find minimum removal of characters ; hash to store frequency of each character ; to set hash array to zeros ; count frequency of each character ; count the odd frequency characters ; if count is - 1 return 0 otherwise return count ; Driver 's Code
#include <iostream> NEW_LINE using namespace std ; #define MAX_CHAR  26 NEW_LINE int minRemoval ( string str ) { int hash [ MAX_CHAR ] ; memset ( hash , 0 , sizeof ( hash ) ) ; for ( int i = 0 ; str [ i ] ; i ++ ) hash [ str [ i ] - ' a ' ] ++ ; int count = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( hash [ i ] % 2 ) count ++ ; return ( count == 0 ) ? 0 : count - 1 ; } int main ( ) { string str = " geeksforgeeks " ; cout << minRemoval ( str ) << endl ; return 0 ; }