Loading problem...
You are exploring documents from an ancient civilization that uses a writing system based on the English alphabet. However, the order of letters in their alphabet differs completely from the standard English order — and this ordering is unknown to you.
Fortunately, you have access to a lexicon containing a list of words that are already sorted in lexicographical order according to this civilization's alphabet rules.
Your task is to analyze the lexicon and deduce the correct ordering of the letters. Return a string containing all unique letters that appear in the lexicon, arranged according to the correct alphabetical order of this foreign language.
Important considerations:
"".words = ["wrt","wrf","er","ett","rftt"]"wertf"Analyzing adjacent words: From "wrt" and "wrf", we learn t < f. From "wrf" and "er", we learn w < e. From "er" and "ett", we learn r < t. From "ett" and "rftt", we learn e < r. Combining these constraints through topological ordering yields: w → e → r → t → f, so the answer is "wertf".
words = ["z","x"]"zx"With only two single-character words, the only constraint is z < x, giving us "zx".
words = ["z","x","z"]""From "z" and "x", we get z < x. From "x" and "z", we get x < z. These constraints contradict each other (z < x and x < z cannot both be true), so no valid ordering exists and we return "".
Constraints