Minimum number of palindromic subsequences to be removed to empty a binary string | 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 subsequences to be removed to make string empty ; If string is empty ; If string is palindrome ; If string is not palindrome ; Driver Code
< ? php function isPalindrome ( $ str ) { $ l = 0 ; $ h = strlen ( $ str ) - 1 ; while ( $ h > $ l ) if ( $ str [ $ l ++ ] != $ str [ $ h -- ] ) return false ; return true ; } function minRemovals ( $ str ) { if ( $ str [ 0 ] == ' ' ) return 0 ; if ( isPalindrome ( $ str ) ) return 1 ; return 2 ; } echo minRemovals ( " 010010 " ) , " STRNEWLINE " ; echo minRemovals ( " 0100101 " ) , " STRNEWLINE " ; ? >