Check if a palindromic string can be obtained by concatenating substrings split from same indices of two given strings | C # program to implement the above approach ; iterate through the length if we could find a [ i ] = = b [ j ] we could increment I and decrement j ; else we could just break the loop as its not a palindrome type sequence ; we could concatenate the a ' s ▁ left ▁ part ▁ + b ' s right part in a variable a and a ' s ▁ right ▁ part + b ' s left in the variable b ; we would check for the palindrome condition if yes we print True else False ; Driver code
using System ; class GFG { static string rev ( string str ) { int st = 0 ; int ed = str . Length - 1 ; char [ ] s = str . ToCharArray ( ) ; while ( st < ed ) { char temp = s [ st ] ; s [ st ] = s [ ed ] ; s [ ed ] = temp ; st ++ ; ed -- ; } return new string ( s ) ; } static bool check ( string a , string b , int n ) { int i = 0 ; int j = n - 1 ; while ( i < n ) { if ( a [ i ] != b [ j ] ) break ; i += 1 ; j -= 1 ; string xa = a . Substring ( i , j + 1 - i ) ; string xb = b . Substring ( i , j + 1 - i ) ; char [ ] XA = xa . ToCharArray ( ) ; Array . Reverse ( XA ) ; char [ ] XB = xb . ToCharArray ( ) ; Array . Reverse ( XB ) ; if ( string . Compare ( xa , new string ( XA ) ) == 0 || string . Compare ( xb , new string ( XB ) ) == 0 ) return true ; } return false ; } static void Main ( ) { string a = " xbdef " ; string b = " cabex " ; if ( check ( a , b , a . Length ) || check ( b , a , a . Length ) ) Console . WriteLine ( " True " ) ; else Console . WriteLine ( " False " ) ; } }