Shortest Transformation
Start Timer
0:00:00
You’re given two words, begin_word
and end_word
which are elements of word_list
.
Write a function shortest_transformation
to find the length of the shortest transformation sequence from begin_word
to end_word
through the elements of word_list
.
Note: Only one letter can be changed at a time and each transformed word in the list must exist inside of word_list
.
Note: In all test cases, a path does exist between begin_word
and end_word
Example:
Input:
Input:
begin_word = "same",
end_word = "cost",
word_list = ["same","came","case","cast","lost","last","cost"]
Output:
def shortest_transformation(begin_word, end_word, word_list) -> 5
Since the transformation sequence would be:
'same' -> 'came' -> 'case' -> 'cast' -> 'cost'
which is five elements long.
Recommended questions for you
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
.
.
.
.
.
Comments