dsa · hard
Word Ladder Length
GreyOrangeGraphQueue
Shortest transformation from begin to end, changing one letter per step, each intermediate in word_list. Return the length (including begin), or 0.
Arguments
begin— the starting wordend— the target cell or end indexword_list— the dictionary of allowed words
**Example**
`` Input: hit cog ["hot","dot","dog","lot","log","cog"] Output: 5 ``
Constraints
word length <= 10, list length <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: hit cog ["hot","dot","dog","lot","log","cog"] Expected: 5