Longest palindrome formed by concatenating and reordering strings of equal length | C # program to find the longest palindrome that can be formed by concatenating and reordering given N Strings of equal length ; Function to print the longest palindrome ; Printing every String in left vector ; Printing the palindromic String in the middle ; Printing the reverse of the right vector to make the readonly output palindromic ; Function to find and print the longest palindrome that can be formed ; Inserting each String in the set ; Lists to add the Strings in the left and right side ; To add the already present palindrome String in the middle of the solution ; Iterating through all the given Strings ; If the String is a palindrome it is added in the middle ; Checking if the reverse of the String is already present in the set ;  ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void printPalindrome ( List < String > left , String mid , List < String > right ) { foreach ( String x in left ) Console . Write ( x ) ; Console . Write ( mid ) ; right . Reverse ( ) ; foreach ( String x in right ) Console . Write ( x ) ; Console . WriteLine ( ) ; } static void findPalindrome ( List < String > S , int N , int M ) { HashSet < String > dict = new HashSet < String > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { dict . Add ( S [ i ] ) ; } List < String > left = new List < String > ( ) , right = new List < String > ( ) ; String mid = " " ; for ( int i = 0 ; i < N ; i ++ ) { String t = S [ i ] ; t = reverse ( t ) ; if ( t == S [ i ] ) mid = t ; else if ( dict . Contains ( t ) ) { left . Add ( S [ i ] ) ; right . Add ( t ) ; dict . Remove ( S [ i ] ) ; dict . Remove ( t ) ; } } printPalindrome ( left , mid , right ) ; } static String reverse ( String input ) { char [ ] a = input . ToCharArray ( ) ; int l , r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . Join ( " " , a ) ; } public static void Main ( String [ ] args ) { String [ ] arr = { " tab " , " one " , " bat " } ; List < String > S = new List < String > ( arr ) ; int M = 3 ; int N = S . Count ; findPalindrome ( S , N , M ) ; } }