Almost linear python solution : O(N) * (7^4)
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst you need to zfill all nums to max num len.\n\nWe are going to create all posible 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst you need to zfill all nums to max num len.\n\nWe are going to create all posible 2 level swaps which would be at most 7^4. because number is less than 10^7.\n\nWe then go reverse on our nums array creating counter dictionary and for every single number we check if its potential swaps exists in our dictionary.\n\n# Complexity\n- Time complexity: O(n *(7^4)) = O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        def rec(num1):\n            ans=set()\n            ans.add(num1)\n            n=len(num1)\n            for i in range(n):\n                for j in range(n):\n                    newnum= list(num1)\n                    newnum[i],newnum[j]=newnum[j],newnum[i]\n                    ans.add("".join(newnum))\n            for num in list(ans):\n                for i in range(n):\n                    for j in range(n):\n                        newnum= list(num)\n                        newnum[i],newnum[j]=newnum[j],newnum[i]\n                        ans.add("".join(newnum))\n            return ans         \n\n        counter= defaultdict(lambda:0)\n        l=len(str(max(nums)))\n        ans=0\n        for num in nums[::-1]:\n            num1=str(num)\n            if len(num1)<l:\n                num1 = ("0"*(l-len(num1)))+num1\n            arr=rec(num1)\n            for r in arr:\n                ans+=counter[r]\n            counter[num1]+=1\n        \n\n        return ans\n```
['Python3']