# Can someone please explain this test case ?

• Input:
"hot", "dot", ["hot","dot","dog"]
"hot", "dog", ["hot","cog","dog","tot","hog","hop","pot","dot"]
"hot", "dog", ["hot","dog","cog","pot","dot"]
Output:
2
Expected:
0

How can the output be 0 for any of these ?
I tried using a depth first search ,I know it sounds stupid after having a dictionary and still using DFS I was just trying to explore different possibilities.

class Solution {
public:
bool diff(string& s1,string s2){
int count=0;
for(int i=0;i<s1.size();i++){
if(count>1)
return 0;
if(s1[i]!=s2[i])
++count;
}
return 1;
}
int helper(string begin,string end,unordered_set<string>& wordList,unordered_set<string>& visited){
if(diff(begin,end))
return 1;
int x=0;
for(const auto& word:wordList){
if(diff(begin,end) && visited.find(word)==visited.end()){
visited.insert(word);
x+=helper(word,end,wordList,visited);
visited.erase(word);
}
}
return x;
}
int ladderLength(string beginWord, string endWord, unordered_set<string>& wordList) {
unordered_set<string> visited;
if(diff(beginWord,endWord))
return 2;
int c=INT_MAX;int y;
for(const auto& word:wordList){
if(diff(beginWord,word)){
visited.insert(word);
y=min(c,1+helper(beginWord,endWord,wordList,visited));
visited.erase(word);
c=y;
}
}
return y;
}
};

• @sujiths52

I got the same questions. Do I misunderstand the problem?
Input:
"a", "c", ["a","b","c"]
"hot", "dog", ["hot","dog"]
"hot", "dog", ["hot","dog","dot"]

expect2

• This post is deleted!

• the real input was

'hot'
'dog'
Set { 'hot', 'dog' }

just simply print input data

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.