Maximum length of string formed by concatenation having even frequency of each character | C # Implementation of the above approach ; Function to check the string ; Count the frequency of the string ; Check the frequency of the string ; Store the Length of the new String ; Function to find the longest concatenated string having every character of even frequency ; Checking the string ; Dont Include the string ; Include the string ; Driver code ; Call the function ; Print the answer
using System ; public class index { static int max = 0 ; static String ans1 = " " ; static void calculate ( String ans ) { int [ ] dp = new int [ 26 ] ; for ( int i = 0 ; i < ans . Length ; ++ i ) { dp [ ( int ) ans [ i ] - ( int ) ' A ' ] ++ ; } for ( int i = 0 ; i < dp . Length ; ++ i ) { if ( dp [ i ] % 2 == 1 ) { return ; } } if ( max < ans . Length ) { max = ans . Length ; ans1 = ans ; } } static void longestString ( String [ ] arr , int index , String str ) { if ( index == arr . Length ) { return ; } longestString ( arr , index + 1 , str ) ; str += arr [ index ] ; calculate ( str ) ; longestString ( arr , index + 1 , str ) ; } public static void Main ( ) { String [ ] A = { " ABAB " , " ABF " , " CDA " , " AD " , " CCC " } ; longestString ( A , 0 , " " ) ; Console . WriteLine ( ans1 + " ▁ " + ans1 . Length ) ; } }