🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line
Please check out LeetCode The Hard Way for more solution explanations and tutorials. \nI\'ll explain my solution line by line daily and you can find the full li
Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \nI\'ll explain my solution line by line daily and you can find the full list in my [Discord](https://discord.gg/Nqm4jJcyBf).\nIf you like it, please give a star, watch my [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way) and upvote this post.\n\n---\n\n<iframe src="https://leetcode.com/playground/UnfxY7Sm/shared" frameBorder="0" width="100%" height="500"></iframe>\n\nAnother Approach using Prime numbers\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<string>> groupAnagrams(vector<string>& strs) {\n        int M = 1e9 + 9;\n        vector<int> primes = {\n            2, 3, 5, 7, 11,\n            13, 17, 19, 23, 29,\n            31, 37, 41, 43, 47,\n            53, 59, 61, 67, 71,\n            73, 79, 83, 89, 97, \n            101\n        };\n\t\t// hacked by ["djrw", "beisx", "ceflvx", "anp"] :D\n        // for (int i = 0; i < 26; i++)  primes[i] = i * i + i + 41;\n        unordered_map<long long, vector<string>> m;\n        for (int i = 0; i < strs.size(); i++) {\n            long long k = 1;\n            for (int j = 0; j < strs[i].size(); j++) {\n                k *= 1LL * primes[strs[i][j] - \'a\'];\n                k %= M;\n            }\n            m[k].push_back(strs[i]);\n        }\n        vector<vector<string>> ans;\n        for (auto x : m) ans.push_back(x.second);\n        return ans;\n    }\n};\n```\n
['C', 'C++']