Interview Query

Shortest Transformation

0
Have you seen this question before?

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.

Next question: Swiping App Design
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code