# Reason About Alien Dictionary Ordering
Given words already sorted according to an unknown alphabet, explain how to infer precedence constraints and produce a valid character ordering, or detect that the input ordering is impossible. The source permits any valid ordering, so discuss the consequence of multiple correct outputs rather than inventing an unstated canonical tie-break.
### Constraints & Assumptions
- Every distinct character appearing in the words belongs to the unknown alphabet.
- Only the first differing character between adjacent words creates a precedence edge.
- A longer word appearing before its exact prefix makes the input invalid.
### Clarifying Questions to Ask
- Must isolated characters appear in the output?
- How should multiple valid orders be handled by an interviewer or test harness?
- Which invalid cases besides directed cycles must be detected?
```hint Compare adjacent words
Derive only the precedence justified by the first differing position; later characters in that pair reveal nothing.
```
### What a Strong Answer Covers
- Graph construction including all characters and prefix-invalid detection.
- Cycle detection or topological ordering and complexity.
- Recognition that zero-indegree choices can create several valid results.
- A testing strategy that validates an order against constraints rather than requiring an arbitrary string.
### Follow-up Questions
1. How would you determine whether the valid ordering is unique?
2. How could a product define a canonical order without changing the original problem?
Overview: Understand Alien Dictionary graph construction, prefix invalidity, cycle detection, and why source-permitted multiple orders need semantic validation.
Given words already sorted according to an unknown alphabet, explain how to infer precedence constraints and produce a valid character ordering, or detect that the input ordering is impossible. The source permits any valid ordering, so discuss the consequence of multiple correct outputs rather than inventing an unstated canonical tie-break.
Constraints & Assumptions
Every distinct character appearing in the words belongs to the unknown alphabet.
Only the first differing character between adjacent words creates a precedence edge.
A longer word appearing before its exact prefix makes the input invalid.
Clarifying Questions to Ask Guidance
Must isolated characters appear in the output?
How should multiple valid orders be handled by an interviewer or test harness?
Which invalid cases besides directed cycles must be detected?
What a Strong Answer Covers Guidance
Graph construction including all characters and prefix-invalid detection.
Cycle detection or topological ordering and complexity.
Recognition that zero-indegree choices can create several valid results.
A testing strategy that validates an order against constraints rather than requiring an arbitrary string.
Follow-up Questions Guidance
How would you determine whether the valid ordering is unique?
How could a product define a canonical order without changing the original problem?