Code Room
CodingHardcod-g746
Subject Topological sortLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given a list of `words` sorted according to the rules of an unknown alphabet. Derive a possible ordering of the distinct letters consistent with that sort. If several orderings are valid, return the lexicographically smallest one (treating letters by normal ASCII for the tie-break). Return the empty string if no valid ordering exists (the input is internally contradictory, e.g. a prefix appears after its extension).

Implement
alien_order(words: list[str]) → str
Examples
in[["wrt","wrf","er","ett","rftt"]]out"wertf"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.