Alien Dictionary
Given a list of words sorted lexicographically by the rules of an unknown alien language, return a string of the language's letters in a valid order. The first place two adjacent words differ reveals that the earlier word's character precedes the later word's character. Return any valid order, or "" if the ordering is contradictory or invalid.
Open official problem prompt ↗Recover a consistent global ordering of the alphabet from local sorted-order evidence between neighboring words.
Like reconstructing a tournament ranking from a list of match results: each 'A beat B' is one edge, and you want a standings list consistent with every result.
- Input
- words = ["wrt", "wrf", "er", "ett", "rftt"]
- Output
- "wertf"
- Why
- Adjacent comparisons give t<f, w<e, r<t, e<r, which linearize to w, e, r, t, f.
1 <= words.length <= 1001 <= words[i].length <= 100words[i] consists of only lowercase English letters