Trains the technique from
LeetCode 269Alien DictionaryThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A retired records system stored its index keys under a custom collation: someone had fixed a private ranking of the symbols, and the system sorted keys by comparing symbols left to right using that ranking, exactly the way a dictionary works. The only surviving artefact is keys, a dump of the index already sorted under that collation, in non-decreasing order. The ranking table itself is gone.
Each key is written with lowercase English letters used as symbols. Rebuild the ranking: return a string that holds every distinct symbol appearing in keys exactly once, written from lowest rank to highest.
A dump usually pins down only part of the ranking, so more than one string can explain it. When that happens, return whichever of those strings comes first when they are compared as ordinary English text. If no ranking of the symbols could have produced the given dump, return an empty string.
Example 1
The first two keys share their opening symbol, so `b` outranks `a` below `c`; the last two show `c` outranks `a` at the opening symbol. That forces `b` and `c` ahead of `a`, and `bca` is the first such string in ordinary text order.
Example 2
The dump only reveals that `e` precedes `s` and that `k` precedes `s`. Every other symbol floats freely, so the earliest ordinary-text string honouring those two facts wins.
Example 3
A key cannot be listed ahead of one of its own openings, whatever the ranking is, so nothing explains this dump.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def collation_order(keys: list[str]) -> str:public String collationOrder(String[] keys)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.