Maximum length of string formed by concatenation having even frequency of each character | Javascript 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
let maxi = 0 ; let ans1 = " " ; function calculate ( ans ) { let dp = new Array ( 26 ) . fill ( 0 ) ; for ( let i = 0 ; i < ans . length ; ++ i ) { dp [ ans [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } for ( let i = 0 ; i < 26 ; ++ i ) { if ( dp [ i ] % 2 == 1 ) { return ; } } if ( maxi < ans . length ) { maxi = ans . length ; ans1 = ans ; } } function longestString ( arr , index , str ) { if ( index == arr . length ) { return ; } longestString ( arr , index + 1 , str ) ; str += arr [ index ] ; calculate ( str ) ; longestString ( arr , index + 1 , str ) ; } let A = [ " " , " " , " " , " " , " " ] ; longestString ( A , 0 , " " ) ; document . write ( ans1 + " " + ans1 . length ) ;