text: Minimum number of palindromic subsequences to be removed to empty a binary string | Java program to count minimum palindromic subsequences to be removed to make an string empty . ; A function to check if a string str is palindrome ; Start from leftmost and rightmost corners of str ; Keep comparing characters while they are same ; Returns count of minimum palindromic subseuqnces to be removed to make string empty ; If string is empty ; If string is palindrome ; If string is not palindrome ; Driver code to test above
code: import java . io . * ; class GFG { static boolean isPalindrome ( String str ) { int l = 0 ; int h = str . length ( ) - 1 ; while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ; return true ; } static int minRemovals ( String str ) { if ( str . charAt ( 0 ) == '') return 0 ; if ( isPalindrome ( str ) ) return 1 ; return 2 ; } public static void main ( String [ ] args ) { System . out . println ( minRemovals ( "010010" ) ) ; System . out . println ( minRemovals ( "0100101" ) ) ; } }