Dashboard
LC #127

Word Ladder

Pattern · ?AmazonGoogleMetaBloomberg

Problem

Transform beginWord into endWord by changing one letter at a time, using only words from wordList. Find the shortest transformation sequence length.

Constraints

  • 1 ≤ beginWord.length ≤ 10
  • beginWord, endWord, wordList[i] all same length
  • All lowercase English letters
  • beginWord ≠ endWord

Example

Input
beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
Output
5
Why
"hit"→"hot"→"dot"→"dog"→"cog" — 5 words, 4 transformations

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗