Not giving correct answer


#1

Can somebody help in fixing the error in this code not getting correct answer ??

Code:
void findword(queue &q, map<string,bool> &mp,string a)
{
int l=a.length();
string b;
b=a;
for(int i=0;i<l;i++)
{
for(int j=0;j<26;j++){
b[i]=‘a’+j;
if(mp.find(b)!=mp.end() && mp[b]==false)
{
q.push(b);
mp[b]=true;
}
}
}

}
int Solution::solve(string a, string b, vector &c)
{
map<string,bool>mp;
int n=c.size(),level=0,cnt=0;
for(int i=0;i<n;i++)
mp[c[i]]=false;
if(mp.find(b)==mp.end())
return 0;

 queue<string> q; 
 q.push(a); 
 mp[a]=true;
 level=1;
 cnt=q.size();  
 while(cnt>0)
 {
     for(int i=0;i<cnt;i++) 
     {
         string temp=q.front();
         q.pop();
         if(temp.compare(b)==0)
         return level; 
         findword(q,mp,a);
     } 
     level++;
     cnt=q.size();
 }   
 return 0;

}