C++ -> Brute Force -> Set Solution [2 Solution]
Intuition\nThink of reverse the each words of the given string and check if the reverse words available or not.\n\n---\n\n\n# Complexity\n- Time complexity:\n1.
# Intuition\nThink of reverse the each words of the given string and check if the reverse words available or not.\n\n---\n\n\n# Complexity\n- Time complexity:\n1. *Brute Force:* **O(n^2)**\n2. *Set:* **O(n)**\n\n- Space complexity:**O(n)**\n\n---\n\n\n**Solution 1 - Brute Force**\n\n```\nclass Solution {\npublic:\n    int maximumNumberOfStringPairs(vector<string>& words) {\n        int n = words.size();\n        vector<string> rev;\n        for(int i=0;i<n;i++)\n        {\n            string str = words[i];\n            reverse(str.begin(),str.end());\n            rev.push_back(str);\n        }\n        int ans = 0;\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(words[i] == rev[j] && i!=j)\n                {\n                    ans++;\n                }\n            }\n        }\n        return ans/2;\n    }\n};\n```\n\n---\n\n\n**Solution 2 - Set**\n```\nclass Solution {\npublic:\n    int maximumNumberOfStringPairs(vector<string>& words) {\n        unordered_set<string> s;\n        int r = 0;\n        for (string &word : words) {\n            sort(word.begin(), word.end());\n            r += !s.insert(word).second;\n        }\n        return r;  \n    }\n};\n```\n\n![upvote.jpeg](https://assets.leetcode.com/users/images/970e1476-e7e6-4150-8f2c-33d33fac059f_1687626500.9282358.jpeg)\n
['C++']