Practice/Uber/Leetcode 127. Word Ladder
CodingMust
You are given a starting word, a target word, and a dictionary of valid words. Your task is to find the shortest sequence of transformations from the starting word to the target word, where:
Return the total number of words in the shortest transformation sequence (including both the start and end words). If no valid transformation sequence exists, return 0.
Example 1:
Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] Output: 5 Explanation: One shortest transformation sequence is: hit -> hot -> dot -> dog -> cog This sequence contains 5 words.
Example 2:
Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"] Output: 0 Explanation: The endWord "cog" is not in the dictionary, so no transformation is possible.
Example 3:
Input: beginWord = "cat", endWord = "hat", wordList = ["hat"] Output: 2 Explanation: cat -> hat (2 words in the sequence)