Recover an alien alphabet from a sorted word list with topological sort

mediumAbout 35 minutesUpdated CodingPrographstopological-sortstrings
Not solved

Share this question

Problem

A dictionary written in an alien language is sorted by the alien alphabet, which uses ordinary characters in an unknown order. Given the dictionary's words in sorted order, work out the alphabet. Write alienOrder(words), which returns a string containing every distinct character that appears in the words, in an order consistent with the dictionary.

alienOrder(["wrt", "wrf", "er", "ett", "rftt"]); // "wertf"
alienOrder(["z", "x"]);                          // "zx"
alienOrder(["z", "x", "z"]);                     // ""  (z before x before z is impossible)

Ref. UR-1421 · © UIRound · uiround.com/questions/recover-an-alien-alphabet-from-a-sorted-word-list-with-topological-sort

Stuck? Take a hint

Try it in the editor

Run your code as often as you like. Submitting it to the full test suite is part of Pro.

Private, and saved in this browser as you type. All your notes are on My lists.

Every question and answer7 days, one payment