Coding Round 2
Senior
programming
**Word Ladder**\nGiven two words, beginWord and endWord, and a dictionary's word list, return the number of words that need to be changed to convert beginWord to endWord. Each transformed word must exist in the word list. Note that you can only change one letter at a time, and the new word must be different from the original.\n\n**Function Signature**: `def ladderLength(beginWord: str, endWord: str, wordList: List[str]) -> int:`\n\n**Example 1**: \n**Input:** beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] \n**Output:** 5 \n**Explanation:** One possible transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", which has a length of 5.\n\n**Example 2**: \n**Input:** beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"] \n**Output:** 0 \n**Explanation:** The endWord is not in the word list, so it cannot be reached.\n\n**Constraints:** \n- 1 <= beginWord.length <= 10 \n- 1 <= endWord.length <= 10 \n- 1 <= wordList.length <= 1000 \n- beginWord != endWord.
Suggested Answer