Hard · Graphs

Alien Dictionary

Given a list of words claimed to be sorted in an alien alphabet's lexicographic order, return a string of the distinct letters that appear in the words, ordered so that the list is sorted under that order (any valid order is accepted), or "" if no letter order sorts the list.

Examples

Example 1

{
  "words": ["wrt", "wrf", "er", "ett", "rftt"]
}

Output: "wertf"

Example 2

{
  "words": ["abc", "ab"]
}

Output: ""

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Graphs problems