C++ brute force
IntuitionApproachComplexity

Time complexity:
n*digit^4


Space complexity:

Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
n*digit^4

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    unordered_set<int> get(int n) {
        string s=to_string(n);
        unordered_set<int> res;
        for (int i1=0;i1<s.size();i1++){
            for(int j1=i1;j1<s.size();j1++){
                swap(s[i1],s[j1]);
                for(int i2=0;i2<s.size();i2++){
                    for(int j2=i2;j2<s.size();j2++){
                        swap(s[i2],s[j2]);
                        res.insert(stoi(s));
                        swap(s[i2],s[j2]);
                    }
                }
                swap(s[i1],s[j1]);
            }
        }
        return res;
    }

    int countPairs(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        
        unordered_map<int,int> past;
        int res=0;
        for (auto x:nums){
            unordered_set<int> g=get(x);
            for(auto y:g) res+=past[y]; 
            past[x]++;
        }
        return res;
    }
};


```
['C++']