VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 11: Graphs

Lesson 11.13 of 16 in this module Unrolled Pro

Alien Dictionary

Recover a letter order from a list of words sorted in an unknown alphabet. From trying every ordering of the letters and checking the list (k! orderings), to reading one 'this letter comes before that one' constraint from each adjacent pair of words and topologically sorting the letters (O(total characters)). Then the invalid prefix case, contradictions that form a cycle, whether the order is unique, and the ML twin: turning pairwise preferences into a ranking.

about 10 min 3 Python examples 2 quick checks

Problem. An alien language uses lowercase English letters in an unknown order. You get a list of words sorted lexicographically in that order. Return a string of all the letters that appear, in an order consistent with the list, or "" if no such order exists.

text
words = ["wrt", "wrf", "er", "ett", "rftt"]   →   "wertf"
words = ["z", "x", "z"]                        →   ""        (z < x and x < z)
words = ["abc", "ab"]                          →   ""        (a longer word can't come before its own prefix)

Sorted order hides constraints: comparing two adjacent words, the first position where they differ says which letter comes first (from "wrt" before "wrf": t < f). Collect those constraints as edges, and a consistent alphabet is a topological order (lesson 11.7) of the letters.

ML context. Inferring an order from pairwise comparisons is a ranking problem: annotators say "response A is better than B", the results of matches say who beat whom, and you want a total order consistent with them. When the comparisons are consistent, it's a topological sort; when they contradict (a cycle), the contradiction must be reported, which is exactly the "" case here (Change D).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Alien Dictionary"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee