hard

Alien Dictionary

You are given a list of words sorted according to the rules of an unknown alphabet. Derive an ordering of the letters that is consistent with the list, or return an empty string if none exists. Any consistent ordering is acceptable.

Constraints
  • 1 ≤ words.length ≤ 100
  • 1 ≤ word length ≤ 100
  • Lowercase English letters
Examples
in: words = ["wrt","wrf","er","ett","rftt"]
out: "wertf"
in: words = ["abc","ab"]
out: ""
A prefix cannot sort after its extension.

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.