Alien Dictionary Order
Updated
Problem statement
A list of words is sorted according to an unknown alphabet over the lowercase English letters that appear in the list.
Return the lexicographically smallest character ordering consistent with the word list. Include every distinct character that appears. Return an empty string when the ordering is impossible because of a cycle or because a longer word appears immediately before a shorter word that matches its beginning.
Function
alienOrder(words: String[]) → StringExamples
Example 1
words = ["wrt","wrf","er","ett","rftt"]return = "wertf"Adjacent word comparisons imply w<e<r<t<f.
Example 2
words = ["z","x","z"]return = ""The list implies both z<x and x<z.
Example 3
words = ["abc","ab"]return = ""A longer word cannot precede its exact prefix in a valid lexicographic order.
Constraints
1 <= words.length <= 10000.1 <= words[i].length <= 100.- Words contain lowercase English letters.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Alien DictionaryByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Infer a Lexicographically Smallest Alien AlphabetMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Recover an Alien Alphabet from Sorted WordsOpenAI · PHONE SCREENOpenAI interview questions
- Letter Order from a Sorted Word ListRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Alien DictionaryAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Validate CSV References and Field DependenciesStripe · PHONE SCREENStripe interview questions
- Alien DictionaryIntuit · OAIntuit interview questions
- Alien DictionaryBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Alien DictionaryAmazon · ONSITE INTERVIEW