Solution: Word Ladder II
Explore the Word Ladder II problem and learn to find all shortest transformation sequences from a begin word to an end word using a two-phase approach. This lesson guides you through breadth-first search to discover shortest paths and depth-first search for backtracking to reconstruct all valid sequences effectively.
We'll cover the following...
Statement
You are given two words, beginWord and endWord, and a dictionary of words called wordList. Your task is to find all the shortest transformation sequences from beginWord to endWord, such that:
Only one letter can be changed at a time.
Each transformed word must exist in the given
wordList.The transformation sequence must begin with
beginWordand end withendWord.
Return all the shortest transformation sequences as a list of lists. If no valid transformation exists, return an empty list.
Constraints:
beginWord.lengthendWord.length == beginWord.lengthwordList.length...