 All Problems
Alien Dictionary
hard
topological sort
graph
string
facebook
google
amazon
airbnb

You are given a list of strings words from an alien language dictionary. The words are sorted lexicographically by the alien language's rules.

Derive the order of letters in the alien alphabet. If no valid order exists, return "".

Example 1:

Input: words = ["wrt","wrf","er","ett","rftt"]
Output: "wertf"

Example 2:

Input: words = ["z","x"]
Output: "zx"

Example 3:

Input: words = ["z","x","z"]
Output: "" (cycle)

Constraints:

  • 1 <= words.length <= 100
  • 1 <= words[i].length <= 100
Run to check your code against the sample cases, or submit to run every case