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

Question

You are given a list of words sorted lexicographically according to the rules of an unknown alien language that uses lowercase English letters. Derive any valid ordering of the alphabet consistent with the input. The order between two letters is implied by the first position at which two adjacent words differ. Return a string of the letters in a valid order; if no valid order exists (a contradiction or the prefix rule is violated, e.g. ['abc','ab']), return the empty string. If multiple orders are valid, return any one of them.

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.