

You are given ‘arr’ = [ “01011”, “010110”, “0111”], Here the strings with the maximum distance between them are “010110” and “0111”, where the prefix is “01”, hence the maximum distance is 4 + 2 = 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 elements of the array ‘arr’.
For each test case, print a single integer representing the maximum distance between any two strings in the array.
Print a separate line for each test case.
1 <= T <= 10
2 <= N <= 10^3
1 <= |arr[i]| <= 10^3
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 check all the possible pairs of strings calculate the maximum distance between all the possible pairs. For each pair, we will traverse from the beginning of each string until they match, then we will remove the matching prefix and add the remaining lengths of the string.
We create a function calculateDistance(firstString, secondString) to get the distance between each pair of strings where firstString and secondString are the strings.
Algorithm:
In this approach, we will maintain a trie and at each node of the trie. We will iterate over all strings and their characters, and for each character, we will store the distance from the end of the string. If the character is ‘0’, we will add the node to the left side, and if the character is ‘1’, we will add it to the right side.
Then we traverse the trie, and at each node, if there are branching nodes, then there is a different string up to with the same prefix up to that node. Then will add the check the distances of their nodes from the end of their respective strings.
We create TrieNode(val) class with left and right pointers, val integer, and isEnd boolean.
We create a function buildTrie(s, root) where s is the strings array and root the root node of the trie.
Algorithm:
Complete String
Complete String
Complete String
Complete String
Complete String
Complete String
Similar Name
Similar Name
Similar Name
Similar Name
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Palindrome Pairs
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System