Reported September 2026
ByteDancegraph

Alien Dictionary

Reported by candidates from ByteDance's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ByteDance OA. Under 2s to a working solution.
Founder's read

The whole ByteDance Alien Dictionary question, reported in September 2026, hinges on a directed graph. Each adjacent word pair gives you at most one edge between two letters, and the answer is a topological order of that graph. The twist here is the lexicographically smallest ordering, so a plain DFS won't cut it. If you've got an OA invite and the graph idea doesn't click, you'll burn your time on string comparisons. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment. Know the shape first: build edges, track indegrees, and pull letters off a min-ordered queue.

The problem

An alien language uses the lowercase English letters, but their order is unknown. You are given an array words that is intended to be sorted from smallest to largest according to that alien alphabet.
Return the lexicographically smallest ordering of every distinct character that makes the dictionary order valid. If no such ordering exists, return the empty string.
For two different words, compare characters from left to right. At the first position where they differ, the character in the earlier word must come before the character in the later word. If all compared characters match, the shorter word must come first.
Each precedence relationship must be counted only once, even if multiple adjacent word pairs imply it.

Function
alienOrder(words: String[]) → String

Examples
Example 1
words = ["wrt","wrf","er","ett","rftt"]
return = "wertf"
The adjacent pairs establish w < e, e < r, r < t, and t < f, so the only valid order is wertf.
Example 2
words = ["za","zb","ca","cb"]
return = "abzc"
The constraints are a < b and z < c. Several orders are valid, and abzc is the lexicographically smallest one.
Example 3
words = ["abc","ab"]
return = ""
A longer word cannot appear before its exact prefix in a sorted dictionary, so no valid alphabet exists.

Constraints
1 <= words.length <= 500
1 <= words[i].length <= 100
The total number of characters across all words is at most 10^4.
Every word contains only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Step one: collect every distinct character, even ones with no edges. Step two: compare each adjacent word pair, find the first differing character, and add an edge from the earlier word's letter to the later word's letter. Use a set so duplicate edges count once, otherwise indegrees get inflated and valid inputs fail. Step three: run Kahn's algorithm with a min-heap (or sorted pick of 26 letters) so ties resolve alphabetically. That gives the smallest valid order, like abzc in example 2. The classic pitfall is the prefix case: if a longer word comes before its own prefix, like abc then ab, return an empty string right away. Also return empty if the output length is less than the distinct letter count, which means a cycle. StealthCoder is your hedge in the live OA if the prefix check or the heap tie-break slips your mind, but the logic is short enough to write cold.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Alien Dictionary cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as alien dictionary. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass ByteDance's OA.

ByteDance reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Alien Dictionary FAQ

What's the trick in ByteDance's Alien Dictionary?+

Treat letters as graph nodes and build one edge per first differing character in adjacent words. Then run topological sort. The ByteDance version asks for the lexicographically smallest order, so use a min-heap for the zero-indegree letters instead of a plain queue.

How hard is this one really?+

It's a hard-tagged graph problem, but the code is about 40 lines. The difficulty is the edge cases: the prefix invalid case, duplicate edges, letters with no constraints, and cycle detection. Get those four right and it's mechanical.

Why must duplicate edges be counted only once?+

If two adjacent pairs both imply a before b, adding the edge twice raises b's indegree to 2. Only one decrement happens when you process a, so b never reaches zero and you wrongly report a cycle. Store edges in a set per letter.

How do I detect an invalid dictionary?+

Two ways. First, if a word is followed by its own strict prefix, return an empty string immediately. Second, after Kahn's algorithm, if the result is shorter than the number of distinct letters, a cycle exists, so return an empty string.

How do I prepare in 48 hours?+

Write this solution from scratch twice. Then do a plain topological sort like Course Schedule II to lock in indegree handling. Practice the min-heap tie-break variant once. Since this was reported in September 2026, graph ordering problems are clearly still in rotation.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ByteDance.

OA at ByteDance?
Invisible during screen share
Get it