hard
Word Ladder
Given a start word, an end word and a dictionary of equal-length words, find the length of the shortest transformation sequence from start to end where each step changes exactly one letter and every intermediate word is in the dictionary. Return 0 if impossible.
Constraints
- 1 ≤ word length ≤ 10
- 1 ≤ wordList.length ≤ 5000
- Lowercase letters, all words distinct
Examples
in: begin = "hit", end = "cog", list = ["hot","dot","dog","lot","log","cog"]
out: 5
hit → hot → dot → dog → cog.
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.