Alien Dictionary Order
Problem statement
A list of words is sorted according to an unknown alphabet over the lowercase English letters that appear in the list.
Return the lexicographically smallest character ordering consistent with the word list. Include every distinct character that appears. Return an empty string when the ordering is impossible because of a cycle or because a longer word appears immediately before its exact prefix.
Function
alienOrder(words: String[]) → StringExamples
Example 1
words = ["wrt","wrf","er","ett","rftt"]return = "wertf"Adjacent word comparisons imply w<e<r<t<f.
Example 2
words = ["z","x","z"]return = ""The list implies both z<x and x<z.
Example 3
words = ["abc","ab"]return = ""A longer word cannot precede its exact prefix in a valid lexicographic order.
Constraints
1 <= words.length <= 10000.1 <= words[i].length <= 100.- Words contain lowercase English letters.