LeetCode 127 Word Ladder - Problem Statement

The problem

Given beginWord, endWord, and a dictionary, find the shortest transformation sequence length from begin to end.

Each transformation changes exactly one letter. Each intermediate word must be in the dictionary.

With beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]:

  • "hit" → "hot" → "dot" → "dog" → "cog"
  • 5 words in the sequence. Answer: 5.

If endWord is not in the dictionary, return 0.

Constraints: Words are same length. Dictionary up to 5000 words.