Hash function h+=(A[i]*A[i]) %mod


#define mod 1000007
int hsh(string s){
int h=0;
for(int i=0;i<s.size();i++){
return h;

vector<vector > Solution::anagrams(const vector &A) {
unordered_map<int,vector> m;
vector<vector> ans;
for(int i=0;i<A.size();i++){
for(auto x:m){
return ans;



Thanks, it was really helpful I was doing the sum of characters as hash


How did you approached to this hash function?


Your code will give wrong output for testcase [“a”,“ab”].
Your function return hash values for both string 1