Maximum length of string formed by concatenation having even frequency of each character | Python3 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
maxi = 0 ; NEW_LINE ans1 = " " ; NEW_LINE def calculate ( ans ) : NEW_LINE INDENT global maxi , ans1 ; NEW_LINE dp = [ 0 ] * 26 ; NEW_LINE for i in range ( len ( ans ) ) : NEW_LINE INDENT dp [ ord ( ans [ i ] ) - ord ( ' A ' ) ] += 1 ; NEW_LINE DEDENT for i in range ( 26 ) : NEW_LINE INDENT if ( dp [ i ] % 2 == 1 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT DEDENT if ( maxi < len ( ans ) ) : NEW_LINE INDENT maxi = len ( ans ) ; NEW_LINE ans1 = ans ; NEW_LINE DEDENT DEDENT def longestString ( arr , index , string ) : NEW_LINE INDENT if ( index == len ( arr ) ) : NEW_LINE INDENT return ; NEW_LINE DEDENT longestString ( arr , index + 1 , string ) ; NEW_LINE string += arr [ index ] ; NEW_LINE calculate ( string ) ; NEW_LINE longestString ( arr , index + 1 , string ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ " ABAB " , " ABF " , " CDA " , " AD " , " CCC " ] ; NEW_LINE longestString ( A , 0 , " " ) ; NEW_LINE print ( ans1 , len ( ans1 ) ) ; NEW_LINE DEDENT