The problem. You're given a beginWord, an endWord and a wordList. A ladder changes one letter at a time, and every word after the first must be in wordList. Return the number of words in the shortest ladder from beginWord to endWord, or 0 if there is none. All words have the same length.
beginWord = "hit", endWord = "cog",
wordList = ["hot","dot","dog","lot","log","cog"] -> 5
beginWord = "hit", endWord = "cog",
wordList = ["hot","dot","dog","lot","log"] -> 0 ("cog" isn't in the list)Members only · free account
The rest of this lesson, with 6 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson