C++ | Sort, Hashmap, Array | Time: O (nlogn) -> O (n), Space: O (n) -> O (1)
Sorting\nTime Complexity: O (n (log n))\nSpace Complexity: Nothing really, but:\n some sorting algorithms do take up space so be mindful of that. \n it can be l
**Sorting**\nTime Complexity: O (n (log n))\nSpace Complexity: Nothing really, but:\n* some sorting algorithms do take up space so be mindful of that. \n* it can be langauge dependent\n```\nclass Solution {\npublic:\n    bool isAnagram(string s, string t) {\n        if (s.size()!=t.size()) return false;\n        \n        sort(s.begin(), s.end());\n        sort(t.begin(), t.end());\n        \n        return s==t;            \n    }\n};\n```\n**Hashmap Solution(s)**\nTime Complexity: O (n)\nSpace Complexity: O(n) (Some may argue it is O (1) because space will be constant, they are correct too.)\n```\nclass Solution {\npublic:\n    bool isAnagram(string s, string t) {\n        if (s.size()!=t.size()) return false;\n        \n\t\tunordered_map <char, int> umap;\n        for (char c:s) umap[c]++;\n        for(char c:t) {\n            umap[c]--;\n            if (umap[c]<0) return false;\n        }\n        \n        return true;\n                    \n    }\n};\n```\n**Another way to write the Hashmap Approach**\nTime Complexity: O (n)\nSpace Complexity: O(n) (Some may argue it is O (1) because space will be constant, they are correct too.)\n```\nclass Solution {\npublic:\n    bool isAnagram(string s, string t) {\n        if (s==t) return true;\n        if (s.size()!=t.size()) return false;\n        unordered_map <char, int> umap;\n        for (int i=0; i<s.size(); i++) {\n            umap[s[i]]++;\n            umap[t[i]]--;\n        }\n        for (auto it: umap) {\n            if (it.second) return false;\n        }\n        return true;\n    }\n};\n```\n**Implementing Hashmap as an Array of constant size**\nTime Complexity: O (n)\nSpace Complexity: O(1) \n```\nclass Solution {\npublic:\n    bool isAnagram(string s, string t) {\n        if (s==t) return true;\n        if (s.size()!=t.size()) return false;\n        int umap[26]={};\n        for (int i=0; i<s.size(); i++) {\n            umap[s[i]-\'a\']++;\n            umap[t[i]-\'a\']--;\n        }\n        for (int i=0; i<26; i++) {\n            if (umap[i]) return false;\n        }\n        return true;\n    }\n};\n```\n
['Array', 'C', 'Sorting', 'C++']