java 4 ms
First calculate the frequnecy arrays, and then check pairs using sliding window.\n\n# Code\n\nclass Solution {\n    public int similarPairs(String[] words) {\n 
First calculate the frequnecy arrays, and then check pairs using sliding window.\n\n# Code\n```\nclass Solution {\n    public int similarPairs(String[] words) {\n        int result = 0;\n        int n = words.length;\n        int[][] freq = new int[n][26];\n        for (int i = 0; i < n; i++) {\n            freq[i] = calculateFrequencyArray(words[i]);\n        }\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = i + 1; j < n; j++) {\n                if (hasSameCharacters(freq[i], freq[j])) {\n                    result++;\n                }\n            }\n        }\n        return result;\n    }\n\n    private  int[] calculateFrequencyArray(String s) {\n        int[] arr = new int[26];\n        for (char ch : s.toCharArray()) {\n            arr[ch - \'a\'] = 1;\n        }\n        return arr;\n    }\n\n    private  boolean hasSameCharacters(int[] arr1, int[] arr2) {\n        for (int i = 0; i < 26; i++) {\n            if (arr1[i] != arr2[i]) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n```
['Java']