Group Anagrams LeetCode

I came across this question where we had to group the strings which were anagrams together.
Please check why isn’t my solution working.


hello @rachitbansal2500
check ur isangram function it is not correct.


consider a case where frequency of evry character of string t is lesser than then character in s.
in that case u will return true but answer should be false.

one simple solution is -> sort the string and then use it as a map key.

idea-> all angram in sorted order looks exaclty same
example- > acb , bca
sort both -> abc,abc,
using this u can easily group all anagrams

Hello! I did the map method and it works well. However, the above function that I have made is completely fine, since I submitted this as a solution for Valid Anagram problem:) The case where you are saying the frequency of each character in string t is < in string s. In that case, there will be some characters which would not be present in string s, therefore for those characters, our code will register the frequency as -1. (because we have already checked the length for both the strings and they must be equal.

yeah right,
i didnt notice that u have checked for equal length as well .

1 Like

Can you please where am I making a mistake now?

declare ans as local vector inside function and then try

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.