Sponsored Reserved space — layout preview until AdSense is connected
hard +45 pts

Word ladder length

BFS on implicit graph.

Implement `word_ladder(begin: str, end: str, word_list: list[str]) -> int`. Each step must be a valid word in word_list. Return 0 if no path exists.

Constraints

All words same length; 1 ≤ len ≤ 10; word_list ≤ 5000.

Example

>>> word_ladder("hit","cog",["hot","dot","dog","lot","log","cog"])
5
45 points ~40 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

BFS; for each word try changing every position to a-z; check against word_set.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected