This is my sample code to check if a given pair of strings are anagram or not.
static bool AreAnagram(string s1, string s2)
{
if (s1.Length != s2.Length)
return false;
foreach (char c in s1)
{
int ix = s2.IndexOf(c);
if (ix == -1)
return false;
s2 = s2.Remove(ix, 1);
}
return true;
}
The complexity of this approach is \$O(n)\$.
What boundary conditions am I missing? Can it be made better?