Simple brute force
Intuition\n Describe your first thoughts on how to solve this problem. \nFind all the possible numbers that can be obtained from each nums[i]\nand check with ot
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFind all the possible numbers that can be obtained from each nums[i]\nand check with other numbers in nums\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nConvert the nums to an hashmap\nIterate through the nums and find all the posiible numbers that you can generete by swapping at most 2 times, add these generated numbers into another hashmap for avoiding duplicate calculations.\nIterate through the second hashmap and count the number of pairs.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n*4096)\nn for itertating through nums and 4096 for genrating all the possible combinations of numbers since the max length of a number can be 8(10000000)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n+4096)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int countPairs(vector<int>& nums) {\n        int n=nums.size();\n        unordered_map<int,int> mp;\n        for(int i:nums) mp[i]++;\n        int ans=0;\n        for(int i=0;i<n;i++){\n            string s1=to_string(nums[i]);\n            unordered_map<int,int> mp1;\n            mp1[nums[i]]++;\n            for(int j=0;j<s1.length();j++){\n                for(int k=j+1;k<s1.length();k++){\n                    swap(s1[j],s1[k]);\n                    mp1[stoi(s1)]++;\n                    \n                    string s2=s1;\n                    for(int l=0;l<s2.length();l++){\n                        for(int m=l+1;m<s2.length();m++){\n                            swap(s2[l],s2[m]);\n                            mp1[stoi(s2)]++;\n                            swap(s2[l],s2[m]);\n                        }\n                    }\n                    \n                    swap(s1[j],s1[k]);\n                }\n            }\n            for(auto& p:mp1){\n                ans+=mp[p.first]-(p.first==nums[i]);\n                if(to_string(p.first).length()!=to_string(nums[i]).length()){\n                    ans+=mp[p.first]-(p.first==nums[i]);\n                }\n                // cout<<p.first<<" "<<ans<<"\\n";\n            }\n        }\n        // cout<<"\\n";\n        return ans/2;\n    }\n};\n```
['C++']