Beats 100% C++ Solution, Using Set. T.C = O(n) & S.C = O(n).
IntuitionUse of Set (Unordered Set)ApproachIterate through the vector from start to finish, checking each element to see if its reverse exists in the set. If th
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Use of Set (Unordered Set)
# Approach
<!-- Describe your approach to solving the problem. -->
Iterate through the vector from start to finish, checking each element to see if its reverse exists in the set. If the reversed string is found, increment the count without adding the current element to the set. If the reversed string is not found, insert the current element into the set. This approach automatically avoids palindrome elements as there are no duplicate elements in the given vector.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n) as we are traversing loop just once. Ignoring the T.C. for reversing the String.
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n) in worst case as we are creating a Set and inserting elements into it.
# Code
```cpp []
class Solution {
public:
    int maximumNumberOfStringPairs(vector<string>& words) {
        int count = 0;
        unordered_set<string> s;
        for(int i=0; i<words.size(); i++) {
            string rev = words[i];
            reverse(rev.begin(), rev.end());
            if(s.find(rev)!=s.end()) count++;
            else s.insert(words[i]);
        }
        return count;
    }
};
```
['C++']