15% off all plans & roadmaps Use code
See plansLeetCode 126 · 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: Every adjacent pair of words differs by a single letter.
Word Ladder II is a Graph Traversal Patterns (DFS & BFS) problem, in the Bidirectional BFS (BFS optimization for known source & target) subpattern. The pattern covers DFS/BFS traversal, topological sort, shortest paths, Union-Find, and MST
Optimize BFS by searching from both source and target simultaneously. Reduce time complexity significantly.
The reference solution runs in O(b^(d/2)) time and O(w * l) space.
Word Ladder II has been reported in interviews at Uber, Amazon, Facebook, Box, Lyft, Microsoft, Google, Bloomberg.
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 II is a Graph Traversal Patterns (DFS & BFS) problem, in the Bidirectional BFS (BFS optimization for known source & target) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.