
Consider ‘arr’ = [‘cha’, ‘r’, ‘act’, ‘ers’], the strings formed with unique characters, [‘cha’, ‘r’, ‘act’, ‘ers’, ‘char’, ‘ract’, ‘chaers’, ‘acters’]. The string with maximum length is ‘chaers’ and ‘acters’ with length 6. Hence the answer is 6.
The first line of input contains the integer ‘T’ representing the number of test cases.
The first line of each test case contains ‘N’ space-separated strings representing the element of the array.
For each test case, print a single integer representing the maximum length of the string of unique characters formed by the concatenation of sub-sequences of the array ‘arr’.
Print a separate line for each test case
1 <= T <= 10
1 <= N <= 26
1 <= |arr[i]| <= 26
arr[i] contains only lowercase letters.
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the function.
In this approach, we will try all the configurations of the string by using a set and applying DFS on the strings array. We will find the path, i.e., the length of the longest string of unique characters till the current position of the array, at any position.
We create dfs(strings, currString, position), where strings are the array of strings given, currString is the current string to be checked, the position is the position of the currString in the given array.
Algorithm:
In this approach, we will try to make all configurations of the string by keeping the bitmask of the characters of the string in an integer, and we will set the initial string result as empty string-:
We will create a function countSetBits(bitSet), where bitSet is the integer whose set bits are counted.
Algorithm: