Problem
An alien language uses the lowercase English letters, but you do not know the order of the letters. You get a list words from the dictionary of this language.
The list words is in the lexical order of the alien language. Lexical order compares two words letter by letter, and the first different letter decides the order. A prefix is a part at the start of a word. If one word is a prefix of the other word, the shorter word comes first.
Return a string with each different letter of words one time, in the alien order. If more than one order is correct, return any of them.
If no order of the letters puts words in lexical order, return an empty string "".
Example 1
- Input:
- words = ["ca","cb","ac","bb"]
- Output:
- "cab"
- Explanation:
- From
"ca"and"cb", the letter a comes before b. From"cb"and"ac", the letter c comes before a.
Example 2
- Input:
- words = ["x","z","x"]
- Output:
- ""
- Explanation:
- The list needs x before z and also z before x. No order of the letters is correct.
Example 3
- Input:
- words = ["pqr","pq"]
- Output:
- ""
- Explanation:
- The word
"pq"is a prefix of"pqr", so"pq"must come first in every order.
Constraints
- 1 <= words.length <= 100
- 1 <= words[i].length <= 100
- words[i] has only lowercase English letters
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Course Schedule
Coding · Breadth-First Search · Depth-First Search · Directed Acyclic Graph
- Evaluate Division
Coding · Array · Bellman–Ford Algorithm · Breadth-First Search
- Find All Possible Recipes from Given Supplies
Coding · Array · Directed Acyclic Graph · Graph Theory
- Loud and Rich
Coding · Array · Depth-First Search · Directed Acyclic Graph
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 5 records
Amazon
Leetcode 269. Alien Dictionary
Reported Aug 31, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceBloomberg
Leetcode 269. Alien Dictionary
Reported Jul 17, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceGoogle
Leetcode 269. Alien Dictionary
Reported Oct 16, 2025 · 2 source reports
STAFF
Source snapshot: Nov 12, 2026
View sourceMeta
Leetcode 269. Alien Dictionary
Reported Mar 11, 2026 · 3 source reports
SENIOR
Source snapshot: Nov 12, 2026
View source