


Return the list of all those words sorted in alphabetical. Return an empty list in case there are no such words
Input: cat, banana, dog, nana, my, walk, walker, baby, dogwalkers, s, babymybaby
Output: babymybaby dogwalkers
Here in the given list of words, you can see that the words babymybaby, dogwalkers contain the words present in the list i.e. ‘s’, 'dog’, ‘walker’,‘baby’ and ‘my’ and both are of the same length.
The first line contains the integer 'N', denoting the number of words that you will be given. Then N lines follow.
Each of the next 'N' lines contains a word denoting the elements of the word ARR.
For the given list of ‘N’ words, print all such words in lexicographical order.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= N <= 1000
1 <= length of longest word <= 100
Where ‘N’ is the given list of words.
Time limit: 1 second
The key observation here is to notice a simple fact that the longest word would be the one whose substring splits in all possible ways are also present in the list.
The algorithm for the same can be as follows:-