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

**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

Open in the Dojo editor