Classify an Alien Dictionary Ordering
Updated
Problem statement
words is intended to be sorted under an unknown alphabet. Derive precedence edges from the first differing character of every adjacent pair and include every observed character.
- Return the unique character order when exactly one topological ordering exists.
- Return
AMBIGUOUSwhen multiple orders are valid. - Return
INVALIDfor a cycle or when a longer word precedes its exact prefix.
Function
alienDictionaryOrder(words: String[]) → StringExamples
Example 1
words = ["wdc","wdr","cd","dd","dr"]return = "wcdr"The adjacent differences force the unique order wcdr.
Example 2
words = ["ab","ac"]return = "AMBIGUOUS"Only b before c is fixed, leaving a unconstrained.
Constraints
0 <= words.length <= 10000- The total number of lowercase letters is at most
100000.
More ZipRecruiter Phone Screen questions
- Neighboring Record IDsPHONE SCREEN · Seen May 2026
- Restaurant Vote LeadersPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
- Most Frequent Word across Grouped ArraysPHONE SCREEN · Seen Sep 2024
- Starting Value with the Longest Collatz ChainPHONE SCREEN · Seen Apr 2022
- Multiset Intersection of Three ListsPHONE SCREEN · Seen Feb 2022
- Find the Smallest Magic IndexPHONE SCREEN · Seen Dec 2021
- Website Pair with the Most Common VisitorsPHONE SCREEN · Seen Nov 2021
- Center-Outward Number SpiralPHONE SCREEN · Seen Jun 2021
- Missing Ranges within Inclusive BoundsPHONE SCREEN · Seen Feb 2021
- Fibonacci Number with Constant Extra SpacePHONE SCREEN · Seen Mar 2017
Similar questions at other companies
- Spreadsheet Formula EvaluatorHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Alien DictionaryByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Parallel Courses IIISnowflake · ONSITE INTERVIEWSnowflake interview questions
- Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
- Course Order and CycleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Choose a Road to Maximize Average Route Toll IncreaseHarness · PHONE SCREEN
- Course Ordering with Concurrent UpdatesNuro · PHONE SCREENNuro interview questions
- Infer a Lexicographically Smallest Alien AlphabetMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Deepest Common Ancestors in a Multi-Parent DAGSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Alien DictionaryBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions