Check and infer custom alphabet
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of string comparison under a custom lexicographic order, the ability to validate whether a list of words is sorted according to that order, and the ability to infer a consistent character precedence from an ordered list.
Check Sorted Order Under Custom Alphabet
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ('hlabcdefgijkmnopqrstuvwxyz', ['hello','leetcode'])
Expected Output: True
Explanation: Alien dictionary example.
Input: ('abcdefghijklmnopqrstuvwxyz', ['apple','app'])
Expected Output: False
Explanation: Prefix violation.
Hints
- Use deterministic tie-breaking for prompts with multiple valid outputs.
- For design-style APIs, simulate operations with explicit inputs.
Infer One Consistent Custom Alphabet
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (['wrt','wrf','er','ett','rftt'],)
Expected Output: 'wertf'
Explanation: Classic ordering.
Input: (['abc','ab'],)
Expected Output: 'impossible'
Explanation: Invalid prefix.
Input: (['z','x','z'],)
Expected Output: 'impossible'
Explanation: Cycle impossible.
Hints
- Use deterministic tie-breaking for prompts with multiple valid outputs.
- For design-style APIs, simulate operations with explicit inputs.