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
function check ( s ) { let a = new Set ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( a . has ( s [ i ] ) ) { return false ; } a . add ( s [ i ] ) ; } return true ; } function helper ( arr , ind ) { let fin = [ ] ; fin . push ( " " ) ; if ( ind == arr . length ) return fin ; let tmp = helper ( arr , ind + 1 ) ; let ret = tmp ; for ( let i = 0 ; i < tmp . length ; i ++ ) { let test = tmp [ i ] + arr [ ind ] ; if ( check ( test ) ) ret . push ( test ) ; } return ret ; } function maxLength ( arr ) { let tmp = helper ( arr , 0 ) ; let len = 0 ; for ( let i = 0 ; i < tmp . length ; i ++ ) { len = len > tmp [ i ] . length ? len : tmp [ i ] . length ; } return len ; } let s = [ ] ; s . push ( " " ) ; document . write ( maxLength ( s ) ) ;