Alien Dictionary
An alien language uses some of the lowercase English letters, but its alphabet puts them in an unknown order. You are given a list words that is claimed to be sorted according to that alphabet. Words are compared the usual way: at the first position where they differ, the word with the earlier letter comes first, and a word always comes before a longer word that it is a prefix of.
Return a string that contains every letter appearing in words exactly once, in an order consistent with the sorted list. If several orders are consistent, return any of them. If no order of the letters could make the list sorted, return the empty string "".
Constraints
1 <= words.length <= 1001 <= words[i].length <= 100words[i]consists of lowercase English letters
Examples
Example 1
Input: words = ["qr","qs","ps","psr","rq"] Output: "qprs"
"qr" before "qs" gives r < s. "qs" before "ps" gives q < p. "ps" before "psr" says nothing (a prefix comes first anyway). "psr" before "rq" gives p < r. The only order is q, p, r, s.
Example 2
Input: words = ["mo","om","mm"] Output: ""
"mo" before "om" means m < o, but "om" before "mm" means o < m. Both can't be true, so return "".
Example 3
Input: words = ["abc","ab"] Output: ""
A word can never come after a longer word that it is a prefix of, whatever the alphabet, so the list is invalid: "".
JavaScript you'll use: Map and Set Strings and characters Graphs and grids in JavaScript
/**
* @param {string[]} words
* @return {string}
*/
function alienOrder(words) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.