Beats 100% java users
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```java []\nimport java.util.*;\n\nclass Solution {\n    String makeDigit(int num, int digits) {\n        String numStr = Integer.toString(num);\n\n        // If the string length is less than the desired size, prepend zeros\n        if (numStr.length() < digits) {\n            StringBuilder sb = new StringBuilder();\n            for (int i = 0; i < digits - numStr.length(); i++) {\n                sb.append(\'0\');\n            }\n            sb.append(numStr);\n            numStr = sb.toString();\n        }\n\n        return numStr;\n    }\n\n    Set<String> makeSwapChanges(int num, int digits) {\n        String s = makeDigit(num, digits);\n        Set<String> poss = new HashSet<>();\n        poss.add(s);\n\n        char[] charArray = s.toCharArray();\n        for (int i = 0; i < digits; ++i) {\n            for (int j = i + 1; j < digits; ++j) {\n                if (charArray[i] != charArray[j]) {\n                    swap(charArray, i, j);\n                    poss.add(new String(charArray));\n                    for (int i1 = 0; i1 < digits; ++i1) {\n                        for (int j1 = 0; j1 < digits; ++j1) {\n                            if (i == i1 && j == j1) continue;\n\n                            if (charArray[i1] != charArray[j1]) {\n                                swap(charArray, i1, j1);\n                                poss.add(new String(charArray));\n                                swap(charArray, j1, i1);\n                            }\n                        }\n                    }\n                    swap(charArray, i, j);\n                }\n            }\n        }\n        return poss;\n    }\n\n    private void swap(char[] array, int i, int j) {\n        char temp = array[i];\n        array[i] = array[j];\n        array[j] = temp;\n    }\n\n    public int countPairs(int[] nums) {\n        int n = nums.length;\n\n        int mx = 0;\n        for (int num : nums) mx = Math.max(mx, num);\n\n        int digits = Integer.toString(mx).length();\n\n        Map<String, Integer> mp = new HashMap<>();\n        mp.put(makeDigit(nums[0], digits), mp.getOrDefault(makeDigit(nums[0], digits), 0) + 1);\n        int ans = 0;\n        for (int i = 1; i < n; ++i) {\n            for (String s : makeSwapChanges(nums[i], digits)) {\n                ans += mp.getOrDefault(s, 0);\n            }\n\n            mp.put(makeDigit(nums[i], digits), mp.getOrDefault(makeDigit(nums[i], digits), 0) + 1);\n        }\n\n        return ans;\n    }\n}\n\n\n```
['Java']