Wrong test cases but I think my code is fine


#1

bool is_anagram(string s1,string s2)
{
if(s1.length()!=s2.length())
{
return false;
}
else
{
map<char,int>m;
int i;
for(i=0;i<s1.length();i++)
{
if(m.find(s1[i])==m.end())
{
m[s1[i]]=1;
}
else
{
m[s1[i]]++;
}
}
for(i=0;i<s2.length();i++)
{
if(m.find(s2[i])==m.end())
{
return false;
}
}
return true;
}
}
vector<vector > Solution::anagrams(const vector &A)
{
vectord;
vector<vector>v;
int i,j;
for(i=0;i<A.size();i++)
{
d.push_back(A[i]);
}
for(i=0;i<d.size();i++)
{
if(d[i]!=“1”)
{
vectorg;
for(j=(i+1);j<d.size();j++)
{
if(is_anagram(d[i],d[j]))
{
if(g.empty())
{
g.push_back(i+1);
}
g.push_back(j+1);
d[j]=“1”;
}
}
if(!g.empty())
{
v.push_back(g);
}
}
}
return v
}


#2

your is_anagram function is wrong.
check for “aab” and “abb”. They are not anagram but your function return true;