

If no such rectangle exists then you need to print 0.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains a single integer ‘N’ denoting the length of the list of words.
The next ‘N’ lines contain a single string denoting the word of the given list.
For each test case, print 0 if no such rectangle exists, else print the maximum area of the rectangle that can be formed.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 100
1 <= | WORD[ i ] | <= 10
WORD[ i ] contains only lowercase English letters.
Where ‘T’ is the number of test cases, ‘N’ is the length of the list and ‘WORD[ i ]’ is the word of the list at index i.
Time limit: 1 sec.
The idea here is to check all rectangles of all possible areas. Let ‘maxlen’ be the maximum length of a word present in the given list. Then max area possible will be less than or equal to maxlen * maxlen because each row and column must represent a word.
So we will be try to form all areas from the maximum possible area of the rectangle that is maxlen * maxlen to 1. First, we will insert all words into a hashmap according to their length. Then we will try to form a word of maximum area. To do this we will keep inserting words row by row from the ‘hashMap’.
Then we check if the current rectangle is valid or not. As all rows are already valid since we have inserted each one of them using hashMap. So we need to check the validity of columns that can be done via trie data structure.
Description of our trie node is shown below.
Our trie data structure basically tells us two things
Algorithm:
Description of DFS function:
This function is used to generate all possible rectangles. It will take arguments :
1. ‘word’ – list of current words of the same size.
2. ‘maxArea’ – variable to store ‘maxArea’
3. ‘maxLen’ – Denoting length of maximum word present in the list.
4. ‘temp’ – An array of strings to store current rectangle.
5. ‘trie’ – A data structure to efficiently search a given word.
void dfs(word, maxArea, maxLen, temp, trie)
Description of isValid function :
This function is used to check whether the current rectangle is valid or not. It will check if all elements in column-wise fashion are present in trie or not.
{bool, bool } isValid(current, trie)