Check if the string has a reversible equal substring at the ends | C # program for the above approach ; Function to print longest substring that appears at beginning of string and also at end in reverse order ; Stores the resultant string ; If the characters are same ; Otherwise , break ; If the string can 't be formed ; Otherwise print resultant string ; Driver Code
using System ; class GFG { static void commonSubstring ( string s ) { int n = s . Length ; int i = 0 ; int j = n - 1 ; string ans = " " ; while ( j >= 0 ) { if ( s [ i ] == s [ j ] ) { ans += s [ i ] ; i ++ ; j -- ; } else { break ; } } if ( ans . Length == 0 ) Console . WriteLine ( " False " ) ; else { Console . WriteLine ( " True ▁ " ) ; Console . WriteLine ( ans ) ; } } public static void Main ( ) { string S = " abca " ; commonSubstring ( S ) ; } }