Back to DSA
Word Ladder
hardStarting from a given word, transform it into a target word by changing one letter at a time. Every intermediate word must exist in a provided dictionary. Find the length of the shortest such transformation chain (counting both endpoints). Return 0 if no chain exists.
Examples
Example 1:
Input:
beginWord = "cat", endWord = "dog", wordList = ["cot","dot","dog","cog","dat"]Output:
4Explanation: cat -> cot -> cog -> dog (4 words).
Example 2:
Input:
beginWord = "run", endWord = "fly", wordList = ["fun","fin","fry"]Output:
0Explanation: The end word 'fly' is not in the dictionary.
Hints
1234567