Check if string is palindrome after removing all consecutive duplicates | C # program for the above approach ; Function to check if a String is palindrome or not ; Length of the String ; Check if its a palindrome ; If the palindromic condition is not met ; Return true as str is palindromic ; Function to check if String str is palindromic after removing every consecutive characters from the str ; Length of the String str ; Create an empty compressed String ; The first character will always be included in the readonly String ; Check all the characters of the String ; If the current character is not same as its previous one , then insert it in the readonly String ; Check if the compressed String is a palindrome ; Driver Code ; Given String ; Function call
using System ; class GFG { static bool isPalindrome ( String str ) { int len = str . Length ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] != str [ len - i - 1 ] ) return false ; } return true ; } static bool isCompressablePalindrome ( String str ) { int len = str . Length ; String compressed = " " ; compressed = String . Join ( " " , str [ 0 ] ) ; for ( int i = 1 ; i < len ; i ++ ) { if ( str [ i ] != str [ i - 1 ] ) compressed += str [ i ] ; } return isPalindrome ( compressed ) ; } public static void Main ( String [ ] args ) { String str = " abbcbbbaaa " ; if ( isCompressablePalindrome ( str ) ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No STRNEWLINE " ) ; } }