my current output is a =3 hack=1 but i am trying to sort d and q then pass it into function so that anagrams will get displayed.how to sort elements like this hack -> achk and rank -> aknr so on… but sort function is not sorting like that. i tried modifying for(i->d.size(){sort(i,i+i.size())} but nothing happened
String Anagram (unable to sort)
approach-
i am trying to make Hack -> ackh Rank will be aknr…like that…aur un sbki frequency array bnado using map.
Phir queries ko b sort kardo…
Aur har ek query k lie dekh lenge kitni hai freq dictionary me
Why you want to sort here?
You can do this without sorting.
Simply For each query, you would have to search for anagrams in the dictionary.
To check for anagram, you can use the map/frequency based approach.
If anagrams are found, you can increment the count and print it.
Another approach can be, while iterating the query, store the query string in a temp variable.Then Sort temp. After that iterate through the dictionary, store the current word of dict in another temp variable say temp2. Sort temp2. Now if temp1==temp2, it means they are anagram. So the current word of the dictionary forms an anagram with the query word.
But this sorting based approach for finding anagrams is not so efficient.
sir i have used map approach but how to make it work without doing sorting.how can i modify my code.please check my code sir.
Thank you sir