Alphabet from a sorted word list
words is a list of words sorted according to an unknown alphabet. Write
alien_order(words) that returns a string of all the letters that appear, in an order
consistent with the list, or "" if the list is contradictory (including a word
appearing after its own longer form, like ["abc", "ab"]). Any consistent order passes.
alien_order(["wrt", "wrf", "er", "ett", "rftt"]) -> "wertf"
alien_order(["z", "x"]) -> "zx"
alien_order(["z", "x", "z"]) -> ""
Each pair of adjacent words gives one constraint from their first differing letter. Then it is a topological sort; a cycle, or a prefix violation, means no answer.
def alien_order(words):
...