As reported: Rivian Senior Software Engineer loop (California, 2025), second coding round: sort a nearly sorted array, and the Alien Dictionary problem.
This is LeetCode 269 — Alien Dictionary. Our write-up: /alien-dictionary.
There is a new alien language that uses the English alphabet, but the order of the letters is unknown. You are given a list of strings words from the language's dictionary, claimed to be sorted lexicographically by the rules of the new language.
If the claim is incorrect and no letter order can produce this arrangement, return "". Otherwise return a string of the unique letters of words in increasing order by the new language's rules. If there are several valid orders, return any of them.
Example 1
Input: words = ["wrt","wrf","er","ett","rftt"]
Output: "wertf"
Example 2
Input: words = ["z","x"]
Output: "zx"
Example 3
Input: words = ["z","x","z"]
Output: ""
Explanation: the order is invalid, so return "".
Constraints: 1 ≤ words.length ≤ 100, 1 ≤ words[i].length ≤ 100, words[i] consists of lowercase English letters.
Code runner: any valid order is accepted — the runner prints ok when your order sorts words, and "" when you return "" for an impossible input.