There is a new alien language that uses the English alphabet, but the order of the letters is unknown.
You are given a list of strings words from the alien language's dictionary. It is claimed that the strings in words are sorted lexicographically by the rules of this new language.
If this claim is incorrect, and the given arrangement of strings in words cannot correspond to any order of letters, return "".
Otherwise, return a string of the unique letters in the new alien language sorted in lexicographically increasing order by the new language's rules. If there are multiple solutions, return any of them.
A string a is lexicographically smaller than a string b if either of the following is true:
a than in b.a is a prefix of b and a.length < b.length.Example 1:
Input: words = ["z","o"]
Output: "zo"
Explanation:
From "z" and "o", we know 'z' < 'o', so return "zo".
Example 2:
Input: words = ["hrn","hrf","er","enn","rfnn"]
Output: "hernf"
Explanation:
"hrn" and "hrf", we know 'n' < 'f'"hrf" and "er", we know 'h' < 'e'"er" and "enn", we know 'r' < 'n'"enn" and "rfnn" we know 'e' < 'r'"hernf"Example 3:
Input: words = ["abc","ab"]
Output: ""
Explanation:
The second word is a prefix of the first word, but the first word appears before the second. This is impossible in a valid lexicographical ordering, so return "".
Constraints:
1 <= words.length <= 1001 <= words[i].length <= 100words[i] consists of only lowercase English letters.Click "Run" or press Ctrl+Enter to execute test cases.