Word Ladder
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
Write ladderLength(begin, end, words). A ladder goes from begin to end one step at a time, where each step changes exactly one letter and keeps the rest in place, and every word after begin, end included, must be in the array words. All the words are lowercase and the same length, begin and end differ, and begin needn't be in words. Return the number of words in the shortest ladder, counting begin and end, or 0 if there's none. For example, ladderLength("hit", "cog", ["hot", "dot", "dog", "lot", "log", "cog"]) is 5: hit, hot, dot, dog, cog. The checks include 7,000 five-letter words.
Your code must pass
- Finds the shortest ladder
- Returns 0 when end isn't in words
- Returns 0 when no ladder reaches end
- Is fast enough for 7,000 words