Problem
You get a start word beginWord, an end word endWord and a list of words wordList. All the words have the same length.
A transformation sequence is a list of words that starts with beginWord and ends with endWord. Each word in the sequence differs from the word before it in exactly one letter.
Every word after beginWord must be in wordList. The word beginWord does not need to be in wordList.
Return the number of words in the shortest transformation sequence. If no sequence exists, return 0.
Example 1
- Input:
- beginWord = "cold", endWord = "warm", wordList = ["cord","card","ward","warm","word","worm"]
- Output:
- 5
- Explanation:
- One shortest sequence is
"cold","cord","card","ward","warm". All 4 letters must change, so no sequence has fewer than 5 words.
Example 2
- Input:
- beginWord = "pin", endWord = "pot", wordList = ["pit","pat","pan"]
- Output:
- 0
- Explanation:
- The word
"pot"is not inwordList, so no sequence can end with it.
Constraints
- 1 <= beginWord.length <= 10
- endWord.length == beginWord.length
- 1 <= wordList.length <= 5000
- wordList[i].length == beginWord.length
- All the words have only lowercase English letters
- beginWord != endWord
- All the words in wordList are unique
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Accounts Merge
Coding · Array · Breadth-First Search · Depth-First Search
- Smallest Common Region
Coding · Array · Binary Lifting · Breadth-First Search
- Smallest String With Swaps
Coding · Array · Breadth-First Search · Depth-First Search
- Shortest Word Distance II
Coding · Array · Design · Hash Table
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 8 records
Amazon
Leetcode 127. Word Ladder
Reported Mar 19, 2026 · 6 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceFan
Leetcode 127. Word Ladder
Reported Apr 15, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMeta
Leetcode 127. Word Ladder
Reported Feb 2, 2026 · 5 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 127. Word Ladder
Reported Mar 12, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source