There is a new alien language that uses the English alphabet. However, the order of the letters is unknown to you.
You are given a list of strings words from the alien language's dictionary, where the strings in words are sorted lexicographically by the rules of this new language.
Derive the order of letters in this language, and return it. If the order is invalid, return an empty string. If there are multiple valid orderings of letters, return any of them.
The insight: When comparing adjacent words, the first differing character tells us about letter ordering. If word1[i] != word2[i], then word1[i] comes before word2[i] in the alien alphabet. This gives us directed edges in a graph.
Real-world analogy: Imagine you're an archaeologist who discovered tablets with words in an unknown ancient language. The tablets are known to be in alphabetical order. By comparing adjacent words, you can deduce the ordering of their alphabet.
words = ["wrt","wrf","er","ett","rftt"]"wertf"words = ["z","x"]"zx"words = ["z","x","z"]""1 <= words.length <= 1001 <= words[i].length <= 100words[i] consists of only lowercase English lettersClick "Run" to execute your code against test cases
Socratic guidance - I'll ask questions, not give answers