Minimum removal to make palindrome permutation | Java 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 code
import java . util . Arrays ; class GFG { static final int MAX_CHAR = 26 ; static int minRemoval ( String str ) { int hash [ ] = new int [ MAX_CHAR ] ; Arrays . fill ( hash , 0 ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) hash [ str . charAt ( i ) - ' a ' ] ++ ; int count = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( hash [ i ] % 2 == 1 ) count ++ ; return ( count == 0 ) ? 0 : count - 1 ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . println ( minRemoval ( str ) ) ; } }