Easiest Solution To ever exist !!!
Intuition\n Describe your first thoughts on how to solve this problem. \nThink about forming all possiblities.\nSee We can perform atmost 2 swaps so form all po
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink about forming all possiblities.\nSee We can perform atmost 2 swaps so form all possible numbers which you can by performing 2 swaps ,\nUse strings to handle data easily\nand then for each possiblity check if it has already occured or not.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1)First convert all the numbers to the maximum length string by converting each number to the number having maxm digits\n2)Try forming all possiblites and check if it has occured previously\nIf yes how many times , add that many times to our answer\n3) Use hash map to maintain how many times the particular string has occured previously.\n\nTADA YOU DID IT !!!.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n*d^4)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n  //try all possilbilites and form all the strings and check if any of \n  //the possible swapping of the current string has already occurred if yes \n  //add it to your answer and then increase the current string freq by 1\n    string cnvt(int num,int dig){\n       string s=to_string(num);\n       int n=s.size();\n       for(int i=0;i<(dig-n);i++){\n        s=\'0\'+s;\n       }\n       return s;\n    }\n    unordered_set<string> allPossible(string s){\n        int n=s.size();\n        unordered_set<string>poss;\n        poss.insert(s);\n        for(int i1=0;i1<n;i1++){\n            for(int j1=i1+1;j1<n;j1++){\n                if(s[i1]!=s[j1]){\n                    swap(s[i1],s[j1]);\n                    poss.insert(s);\n                     for(int i2=0;i2<n;i2++){\n            for(int j2=i2+1;j2<n;j2++){\n                if(s[i2]!=s[j2] && i1!=i2 && j1!=j2){\n                     swap(s[i2],s[j2]);\n                     poss.insert(s);\n                     swap(s[i2],s[j2]);\n                }\n            }\n                     }\n                     swap(s[i1],s[j1]);\n                }\n            }\n        }\n        return poss;\n    }\n    int countPairs(vector<int>& nums) {\n        int n=nums.size();\n        int maxi=*max_element(nums.begin(),nums.end());\n        int digits=to_string(maxi).size();\n\n        vector<string>arr;\n        for(int i=0;i<n;i++){\n           string temp=cnvt(nums[i],digits);\n           arr.push_back(temp);\n        }\n        int ans=0;\n        unordered_map<string,int>mp;\n        for(int i=0;i<n;i++){\n            unordered_set<string>temp=allPossible(arr[i]);\n            for(auto it:temp){\n                ans+=mp[it];\n            }\n            mp[arr[i]]++;\n        }\n        return ans;\n\n    }\n};\n```
['Array', 'Hash Table', 'Combinatorics', 'Ordered Set', 'C++']