Word Ladder
Return the length of the shortest transformation from beginWord to endWord.
Examples
Input: ["hit","cog",["hot","dot","dog","lot","log","cog"]]
Output: 5
Input: ["hit","cog",["hot","dot","dog","lot","log"]]
Output: 0
Hints
Model the problem as a graph where each word is a node, and edges exist between words that differ by exactly one character. The transformation sequence is a path in this graph.
Use BFS starting from `beginWord` to explore all possible one-letter transformations level by level, tracking visited words to avoid cycles and ensure the shortest path is found.
Optimize by precomputing possible one-letter transformations for each word in the `wordList` (e.g., using a wildcard map like `*ot` → `["hot", "dot", "lot"]`) to reduce the branching factor during BFS.
Related Problems
Word Ladder
Return the length of the shortest transformation from beginWord to endWord.