


Input: 'WORDS' = ["ninjas", "coding", "codingninjas"]
Output: ["codingninjas"]
Only word "codingninjas' is formed after concatenating two or more words in the list i.e "coding" and "ninjas".
The first line of input contains an integer 'T', denoting the number of test cases.
The first line contains an integer 'N' size of the list 'WORDS' for each test case. The next line contains 'N' words
For each test case, print all the formed words after concatenating two or more words in the input list.
Output for each test case will be printed in a separate line.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10
2 <= 'N' <= 10^2
1 <= 'WORDS[i].LENGTH'<= 10^2
Time Limit: 1 sec
Algorithm :
compare(a, b):
‘get’ function will return true if current word is formed after concatenating some strings in input array or not else it will return false.
By storing the above data in the 'wordDp' map, we will decrease the time complexity from factorial to the polynomial.
Algorithm :
compare(a, b):
‘get’ function will return true if current word is formed after concatening some strings in input array or not else it will return false.
Approach: We will implement the same above logic iteratively in this approach. The main observation is that for any word formed after concatenation, there must be at least three indexes (at least one besides 0 and n-1, which n is the length of the word), which can be used to split the whole string into at least two substrings and all substrings can be found in words.
We will iterate over all the words and, for each word, will keep track of the till what index we can form the substrings using the 'DP' array.
Algorithm :