Works in Java, TLE in python, super simple solution.
Intuition\nThe hint given after the contest was the intuiton.\n\n# Code\njava []\nimport java.util.*;\n\nclass Solution {\n    public HashSet<Integer> get_possi
# Intuition\nThe hint given after the contest was the intuiton.\n\n# Code\n```java []\nimport java.util.*;\n\nclass Solution {\n    public HashSet<Integer> get_possible_integers(int num) {\n        HashSet<Integer> possibleSwaps = new HashSet<>();\n        // find out all the possible combination of swaps\n        possibleSwaps.add(num);\n        String numStr = String.format("%07d", num);\n                        \n        for (int i = 0; i < 7; i++) {\n            for (int j = i; j < 7; j++) {\n                for (int k = 0; k < 7; k++) {\n                    for (int l = k; l < 7; l++) {\n                        // pad it with 0\'s to avoid index out of bounds\n                        char[] option = new char[7];\n                        Arrays.fill(option, \'0\');\n                        System.arraycopy(numStr.toCharArray(), 0, option, 7 - numStr.length(), numStr.length());\n                        \n                        // swap i, j and k, l \n                        // where i could be j and k could be l\n                        // so this considers atmost 2 swaps\n                        char temp1 = option[i];\n                        option[i] = option[j];\n                        option[j] = temp1;\n                        \n                        char temp2 = option[k];\n                        option[k] = option[l];\n                        option[l] = temp2;\n                        \n                        // convert option back to int\n                        possibleSwaps.add(Integer.parseInt(new String(option)));\n                    }\n                }\n            }\n        }\n        return possibleSwaps;\n    }\n\n    public int countPairs(int[] nums) {\n        Map<Integer, Integer> pairCandidates = new HashMap<>();\n        int pairCount = 0;\n        for (int num : nums) {\n            pairCount += pairCandidates.getOrDefault(num, 0);\n            HashSet<Integer> possibleSwaps = get_possible_integers(num);\n            for (int swap : possibleSwaps) {\n                pairCandidates.put(swap, pairCandidates.getOrDefault(swap, 0) + 1);\n            }\n        }\n        return pairCount;\n    }\n}\n```\n```python []\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        def get_possible_integers(num):\n            possible_swaps = set()\n            # find out all the possible combination of swaps\n            possible_swaps.add(num)\n            num_str = str(num)\n                        \n            for i in range(7):\n                for j in range(i, 7):\n                    for k in range(7):\n                        for l in range(k, 7):\n                            # pad it with 0\'s to avoid index out of bounds\n                            option = list(\'0\' * (7 - len(num_str)) + num_str)\n                            # swap i, j and k, l \n                            # where i could be j and k could be l\n                            # so this considers atmost 2 swaps\n                            option[i], option[j] = option[j], option[i]\n                            option[k], option[l] = option[l], option[k]\n                            # convert option back to int\n                            possible_swaps.add(int("".join(option)))\n            return possible_swaps\n\n        pair_candidates = defaultdict(int)\n        pair_count = 0\n        for num in nums:\n            pair_count += pair_candidates[num]\n            possible_swaps = get_possible_integers(num)\n            for swap in possible_swaps:\n                pair_candidates[swap] += 1\n        \n        return pair_count\n```
['Java', 'Python3']