How to check if two strings are anagram or not?

strings “silent” and “listen” are anagrams.

Then, we discuss all the possible valid test cases to write the algorithm such as length should match, duplicates are not allowed, and words should be only alphabetic in nature.

Pseudo Code: -

bool checkAnagram(string S1, int m, string S2, int n)
   if ( m != n )
        return False
   sort(S1, m)
   sort(S2, n)
   for ( i = 0 to n-1 )
      if ( S1[i] != S2[i] )
            return False
   return True