Maximize length of the String by concatenating characters from an Array of Strings | C # program to implement the above approach ; 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
using System ; using System . Collections ; using System . Collections . Generic ; using System . Text ; class GFG { static bool check ( string s ) { HashSet < char > a = new HashSet < char > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( a . Contains ( s [ i ] ) ) { return false ; } a . Add ( s [ i ] ) ; } return true ; } static ArrayList helper ( ArrayList arr , int ind ) { if ( ind == arr . Count ) return new ArrayList ( ) { " " } ; ArrayList tmp = helper ( arr , ind + 1 ) ; ArrayList ret = new ArrayList ( tmp ) ; for ( int i = 0 ; i < tmp . Count ; i ++ ) { string test = ( string ) tmp [ i ] + ( string ) arr [ ind ] ; if ( check ( test ) ) ret . Add ( test ) ; } return ret ; } static int maxLength ( ArrayList arr ) { ArrayList tmp = helper ( arr , 0 ) ; int len = 0 ; for ( int i = 0 ; i < tmp . Count ; i ++ ) { len = len > ( ( string ) tmp [ i ] ) . Length ? len : ( ( string ) tmp [ i ] ) . Length ; } return len ; } public static void Main ( string [ ] args ) { ArrayList s = new ArrayList ( ) ; s . Add ( " abcdefgh " ) ; Console . Write ( maxLength ( s ) ) ; } }