15% off all plans & roadmaps Use code
See plansLeetCode 127 · Solution & editorial
A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:
Word Ladder is a Graph Traversal Patterns (DFS & BFS) problem, in the Graph BFS - Connected Components / Island Counting subpattern. The pattern covers DFS/BFS traversal, topological sort, shortest paths, Union-Find, and MST
Use BFS for shortest path in unweighted graphs. Solve word ladder, rotting oranges, and matrix problems.
The reference solution runs in O(N * L^2) time and O(N * L) space.
Word Ladder has been reported in interviews at Amazon, Facebook, Lyft, Microsoft, Google, Uber, Bloomberg, Qualtrics.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Word Ladder is a Graph Traversal Patterns (DFS & BFS) problem, in the Graph BFS - Connected Components / Island Counting subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.