Word Ladder
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. * Every `si` for `1 <= i <= k` is in `wordList`. (beginWord does not need to be in wordList). * `sk == endWord`. Given two words, `beginWord` and `endWord`, and a dictionary `wordList`, return the number of words in the shortest transformation sequence from `beginWord` to `endWord`, or `0` if no such sequence exists. **Examples:** ```typescript ladderLength("hit", "cog", ["hot","dot","dog","lot","log","cog"]) // 5 ladderLength("hit", "cog", ["hot","dot","dog","lot","log"]) // 0 ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(M^2 * N)
- Space complexity: O(M * N)
BFS explores words of length M across dictionary of size N.
Follow-Up Questions Interviewers Ask About Word Ladder
- How can bidirectional BFS optimize Word Ladder?
Search simultaneously from beginWord and endWord, meeting in the middle to reduce search space branching from b^d to 2 * b^(d/2).
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.