Simple Brute force Solution
Code\ncpp []\nclass Solution {\npublic:\n    unordered_set<int> f(int a) {\n        unordered_set<int> st;\n        string s=to_string(a);\n        for(int i=0;
# Code\n```cpp []\nclass Solution {\npublic:\n    unordered_set<int> f(int a) {\n        unordered_set<int> st;\n        string s=to_string(a);\n        for(int i=0;i<s.size();i++) {\n            for(int j=i+1;j<s.size();j++) {\n                string temp=s;\n                swap(temp[i],temp[j]);\n                st.insert(stoi(temp));\n                for(int k1=0;k1<s.size();k1++) {\n                    for(int k2=k1+1;k2<s.size();k2++) {\n                        string tmp=temp;\n                        swap(tmp[k1],tmp[k2]);\n                        st.insert(stoi(tmp));\n                    }\n                }\n            }\n        }\n        return st;\n    }\n    int countPairs(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        map<int,int> mp;\n        int cnt=0,n=nums.size();\n        for(int i=0;i<n;i++) {\n            unordered_set<int> st=f(nums[i]);\n            for(auto it:st) {\n                cnt+=mp[it];\n            }\n            mp[nums[i]]++;\n        }\n        for(auto it:mp) {\n            if(it.first/10==0) {\n                cnt+=it.second*(it.second-1)/2;\n            }\n        }\n        return cnt;\n    }\n};\n```
['C++']