Alien Dictionary
Updated
Problem statement
Given an array words that is meant to be sorted from smallest to largest in an alien alphabet, return an order of every distinct character that fits this sorting. The alien language uses the lowercase English letters, but their order is unknown.
If several orders fit, return the lexicographically smallest one, which is the one that comes first in normal alphabet order. If no order fits, return the empty string.
To compare two different words, go character by character from the left. At the first position where they differ, the character in the earlier word must come first in the alien alphabet. If all compared characters match, the shorter word must come first.
If several pairs of neighboring words give the same rule (one character before another), count that rule only once.
Function
alienOrder(words: String[]) → StringExamples
Example 1
words = ["wrt","wrf","er","ett","rftt"]return = "wertf"Neighboring words give w < e, e < r, r < t, and t < f, so the only order that fits is wertf.
Example 2
words = ["za","zb","ca","cb"]return = "abzc"Neighboring words give a < b and z < c. Several orders fit, and abzc comes first in normal alphabet order.
Example 3
words = ["abc","ab"]return = ""abc comes before its own prefix ab, which no alphabet allows, so the answer is the empty string.
Constraints
1 <= words.length <= 5001 <= words[i].length <= 100- The total number of characters across all words is at most
10^4. - Every word contains only lowercase English letters.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 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
- Alien DictionaryAmazon · ONSITE INTERVIEW
- 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
- Can Subsequences Share One Master Sequence?Google · ONSITE INTERVIEWGoogle interview questions
- Password From Ordering HintsRogo · ONSITE INTERVIEW
- Alien DictionaryIntuit · OAIntuit interview questions
- Recover an Alien Alphabet from Sorted WordsOpenAI · PHONE SCREENOpenAI interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)