Tap here to switch tabs
Problem
Ask
Submissions

Problem: Word Ladder II

hard
40 min
Explore how to implement backtracking to find all shortest transformation sequences from a start word to an end word using a given dictionary. Understand the constraints of changing only one letter at a time and ensure all transformed words exist in the word list. This lesson helps you develop skills to solve complex word transformation problems efficiently.

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

  • wordList[i].length == beginWord.length

  • beginWordendWord, and wordList[i] consist of lowercase English letters.

  • beginWord != endWord

  • All the words in wordList are unique.

  • The sum of all shortest transformation sequences does not exceed 10510^5.

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Word Ladder II

hard
40 min
Explore how to implement backtracking to find all shortest transformation sequences from a start word to an end word using a given dictionary. Understand the constraints of changing only one letter at a time and ensure all transformed words exist in the word list. This lesson helps you develop skills to solve complex word transformation problems efficiently.

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

  • wordList[i].length == beginWord.length

  • beginWordendWord, and wordList[i] consist of lowercase English letters.

  • beginWord != endWord

  • All the words in wordList are unique.

  • The sum of all shortest transformation sequences does not exceed 10510^5.