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.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.