Minimum removal to make palindrome permutation | function to find minimum removal of characters ; hash to store frequency of each character and 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 Code
< ? php function minRemoval ( $ str ) { $ hash = array_fill ( 0 , 26 , 0 ) ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) $ hash [ ord ( $ str [ $ i ] ) - 97 ] ++ ; $ count = 0 ; for ( $ i = 0 ; $ i < 26 ; $ i ++ ) if ( $ hash [ $ i ] % 2 ) $ count ++ ; return ( $ count == 0 ) ? 0 : $ count - 1 ; } $ str = " geeksforgeeks " ; echo minRemoval ( $ str ) . " STRNEWLINE " ; ? >