Word Ladder

A transformation sequence from the word beginWord to the word endWord using a dictionary wordList is a sequence of words such that every adjacent pair of words differs by a single letter, each subsequent word is in the wordList, and the last word is endWord. Return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no sequence exists.

Constraints

  • 1 <= beginWord.length <= 10
  • endWord.length == beginWord.length
  • 1 <= wordList.length <= 5000
  • wordList[i].length == beginWord.length
  • beginWord, endWord, and wordList[i] consist of lowercase English letters.
  • beginWord != endWord
  • All the words in wordList are unique.
Saving… · 2 lines
class Solution:
def wordLadder(self, beginWord: str, endWord: str, wordList: List[str]) -> int:
Console

Click Run to execute sample tests.