Backtracking problems
127 Word Ladder #
SO you are give 2 words one is the starting point and other is the ending point. Since it’s shortest path, you use BFS. So using BFS we are going to store each string in our sequence & then going to have integer value called changes which will be eventually returned from our function, which will keep track of how many changes do we have in sequence.
class Solution{
public:
int ladderLength(std::string beginWord, std::string endWord, std::vector<std::string> wordList){
std::set<std::string> set(wordList.begin(), wordList.end());
if(!set.find(endWord)) return 0;
std::queue queue;
queue.add(beginWord);
}
};