Maximize length of the String by concatenating characters from an Array of Strings | Function to check if all the string characters are unique ; Check for repetition in characters ; Function to generate all possible strings from the given array ; Base case ; Consider every string as a starting substring and store the generated string ; Add current string to result of other strings and check if characters are unique or not ; Function to find the maximum possible length of a string ; Return max length possible ; Return the answer ; Driver Code
def check ( s ) : NEW_LINE INDENT a = set ( ) NEW_LINE for i in s : NEW_LINE INDENT if i in a : NEW_LINE INDENT return False NEW_LINE DEDENT a . add ( i ) NEW_LINE DEDENT return True NEW_LINE DEDENT def helper ( arr , ind ) : NEW_LINE INDENT if ( ind == len ( arr ) ) : NEW_LINE INDENT return [ " " ] NEW_LINE DEDENT tmp = helper ( arr , ind + 1 ) NEW_LINE ret = tmp NEW_LINE for i in tmp : NEW_LINE INDENT test = i + arr [ ind ] NEW_LINE if ( check ( test ) ) : NEW_LINE INDENT ret . append ( test ) NEW_LINE DEDENT DEDENT return ret NEW_LINE DEDENT def maxLength ( arr ) : NEW_LINE INDENT tmp = helper ( arr , 0 ) NEW_LINE l = 0 NEW_LINE for i in tmp : NEW_LINE INDENT l = l if l > len ( i ) else len ( i ) NEW_LINE DEDENT return l NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = [ ] NEW_LINE s . append ( " abcdefgh " ) NEW_LINE print ( maxLength ( s ) ) NEW_LINE DEDENT