You are given two words, beginWord and endWord, and a dictionary of words wordList.
Your task is to find the length of the shortest transformation sequence from beginWord to endWord.
You may assume that:
beginWord) must be present in wordList.beginWord does not need to be in wordList.Return the length of the shortest transformation sequence or 0 if no such transformation sequence exists.
beginWord = "bat"
endWord = "cat"
wordList = ["bat", "rat", "cat"]
2
"bat" can be transformed to "cat" by changing 'b' to 'c'.
beginWord = "cold"
endWord = "warm"
wordList = ["cold", "cord", "card", "ward", "warm"]
5
One possible transformation sequence is "cold" -> "cord" -> "card" -> "ward" -> "warm".
beginWord = "lamp"
endWord = "fork"
wordList = ["lamp", "lamb", "limb", "lime", "like", "bike", "bake", "bake", "bake", "fork"]
0
There is no possible transformation sequence from "lamp" to "fork" using the provided word list.
beginWord = "bat"
endWord = "cat"
wordList = ["bat", "rat", "cat"]
2