Word Ladder
Hard
Graphs
BFS
Find shortest transformation from begin to end word, changing one letter at a time.
Input line 1: beginWord
Input line 2: endWord
Input line 3: comma-separated wordList
Output: length of shortest transformation (0 if impossible)
Constraints
See problem-specific constraints. Optimized solution required.
Examples
Example 1:
Input: hit
cog
hot,dot,dog,lot,log,cog
Output:
Example 2:
Input: hit
cog
hot,dot,dog,lot,log,cog
Output:
Hints
Consider a bfs approach.
Think about time complexity.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console