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
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.