Anagram--Can you tel me what is the problem in my code?When i submit it shows wrong answer...

My solution is here


ur solution fails for the following case:



aaaa aaaa

ur output: NO

actual output:YES

This is because the values of

  • count1=16
  • count2=4

Working code(with some editing):

Other suggestions:

  • there is an inbuilt function strlen() available to find the length of string
  • add ‘\n’ to printf(“NO”) in len1!=len2 condition
  • u can solve this question by either sorting s1 and s2 then comparing them, or find the frequencey of each alphabet and compare them
1 Like

Thnx a lot.It’s really helpful.

Happy to have helped :slight_smile: