242. Word Ladder — BFS Shortest Transformation
Hard · Breadth-First Search
Given a `beginWord`, `endWord`, and a `wordList`, find the length of the shortest transformation sequence from `beginWord` to `endWord` where each step changes exactly one letter and every intermediate word must be in `wordList`. Return 0 if no path exists.
Examples
Example 1 Input: beginWord="hit", endWord="cog", wordList=["hot","dot","dog","lot","log","cog"] Output: 5 Explanation: hit→hot→dot→dog→cog (length 5)
Constraints
- 1 ≤ words.length ≤ 5000, 1 ≤ word.length ≤ 10