In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is unknown to you. You are given a list of words from the alien language, sorted lexicographically by the rules of this new language. Derive the order of letters in this language.
words
: A list of strings representing the words in the alien language.Sample Input:
words = ["wrt", "wrf", "er", "ett", "rftt"]
Output:
"wertf"
Think about how you can use graph theory to solve this problem. Consider constructing a graph where each node is a character and edges represent the order between characters. Then, perform a topological sort to determine the order of characters.
This problem is a standard coding question you see on LeetCode. You can find the original problem here.