Alien Dictionary
Updated
Problem statement
The words are sorted using an unknown alphabet. Return an ordering of every distinct letter that appears in the words, consistent with that sorted order.
If several orderings work, return the lexicographically smallest ordering under ordinary English letter order. Return an empty string if no ordering works.
Words are compared at their first differing letter. If one word is a prefix of another, the shorter word must appear first. Only letters present in the input belong in the result.
Function
alienOrder(words: String[]) → StringExamples
Example 1
words = ["wrt","wrf","er","ett","rftt"]return = "wertf"The first differing letters give t before f, w before e, r before t, and e before r. The resulting order is wertf.
Example 2
words = ["ab","ac"]return = "abc"Only b before c is required. Among valid orderings of a, b, and c, abc is the smallest.
Constraints
- 1 <= words.length <= 1000
- 1 <= words[i].length <= 100
- Every word contains only lowercase English letters.
More Citadel Phone Screen questions
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
- Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
- Exchange BBO and Market-Wide NBBOPHONE SCREEN · Seen Sep 2026
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN
- Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Dependency-Aware Task SchedulerRippling · PHONE SCREENRippling interview questions
- Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Build Packages as Dependencies Are DiscoveredMongoDB · PHONE SCREENMongoDB interview questions
- Lexicographic Dependency OrderIllumio · PHONE SCREENIllumio interview questions
- Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions