65.3k views
2 votes
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:

Only one letter can be changed at a time
Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
For example,
Given:
beginWord = ""hit""
endWord = ""cog""
wordList = [""hot"",""dot"",""dog"",""lot"",""log"",""cog""]
Return
[
[""hit"",""hot"",""dot"",""dog"",""cog""],
[""hit"",""hot"",""lot"",""log"",""cog""]
]
Note:
Return an empty list if there is no such transformation sequence.
All words have the same length.
All words contain only lowercase alphabetic characters.
ou may assume no duplicates in the word list.
You may assume beginWord and endWord are non-empty and are not the same.

1 Answer

4 votes

Final answer:

The problem involves finding sequences of words that transform the beginWord to the endWord by altering one letter at a time, using only words from the provided word list, illustrated by changing "hit" to "cog" via two different paths.

Step-by-step explanation:

The question is about finding all the shortest transformation sequences that change one word to another by altering only one letter at a time. Each changed word must be present in the given word list. Using the example provided, where the beginWord is "hit", the endWord is "cog", and the wordList includes "hot", "dot", "dog", "lot", "log", "cog", the transformation sequences are: ["hit","hot","dot","dog","cog"] and ["hit","hot","lot","log","cog"]. These sequences show the process of changing one letter at a time while using only words present in the word list.

User Bunbun
by
9.2k points