Search⌘ K
AI Features

Solution: Word Ladder II

Explore how to solve Word Ladder II by mastering the combined BFS and backtracking approach. Discover how to efficiently find all shortest transformation sequences between words using breadth-first search for shortest path discovery and depth-first search backtracking for reconstructing all valid sequences.

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:

  1. Only one letter can be changed at a time.

  2. Each transformed word must exist in the given wordList.

  3. The transformation sequence must begin with beginWord and end with endWord.

Return all the shortest transformation sequences as a list of lists. If no valid transformation exists, return an empty list.

Constraints:

  • 11 \leq beginWord.length 5\leq 5

  • endWord.length == beginWord.length

  • 11 \leq wordList.length 500\leq 500 ...