CHECK MY SOLUTION 👇👇
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nfrom collections import defaultdict\n\nclass Solution:\n    def makeDigit(self, num, digits):\n        s = str(num)\n        return s.zfill(digits)\n\n    def makeSwapChanges(self, num, digits):\n        s = self.makeDigit(num, digits)\n        poss = set()\n        poss.add(s)\n\n        for i in range(digits):\n            for j in range(i + 1, digits):\n                # Convert string to a list for swapping\n                s_list = list(s)\n                # Perform the first swap\n                s_list[i], s_list[j] = s_list[j], s_list[i]\n                swapped_s = \'\'.join(s_list)\n                poss.add(swapped_s)\n\n                for i1 in range(digits):\n                    for j1 in range(i1 + 1, digits):\n                        if s_list[i1] != s_list[j1]:\n                            s_list[i1], s_list[j1] = s_list[j1], s_list[i1]\n                            poss.add(\'\'.join(s_list))\n                            # Revert the second swap\n                            s_list[j1], s_list[i1] = s_list[i1], s_list[j1]\n\n                # Revert the first swap\n                s_list[i], s_list[j] = s_list[j], s_list[i]\n                s = \'\'.join(s_list)\n\n        return poss\n\n    def countPairs(self, nums):\n        n = len(nums)\n        digits = len(str(max(nums)))\n        mp = defaultdict(int)\n        ans = 0\n\n        for num in nums:\n            for s in self.makeSwapChanges(num, digits):\n                if s in mp:\n                    ans += mp[s]\n            mp[self.makeDigit(num, digits)] += 1\n\n        return ans\n\n```
['Python3']