JAVA | Brute force using set / array
Please Upvote :D\n---\n##### 1. Using hashset (Slow):\njava []\nclass Solution {\n    public int similarPairs(String[] words) {\n        int n = words.length, c
# Please Upvote :D\n---\n##### 1. Using hashset (Slow):\n``` java []\nclass Solution {\n    public int similarPairs(String[] words) {\n        int n = words.length, count = 0;\n        Set<Character> set1, set2;\n\n        for (int i = 0; i < n - 1; i++) {\n            set1 = new HashSet<>();\n            for (char c : words[i].toCharArray()) {\n                set1.add(c);\n            }\n            for (int j = i + 1; j < n; j++) {\n                set2 = new HashSet<>();\n                for (char c : words[j].toCharArray()) {\n                    set2.add(c);\n                }\n                if (set1.equals(set2)) count++;\n            }\n        }\n\n        return count;\n    }\n}\n\n\n// TC: O(n^2 * k)\n// n is the length of array and k is the length of word in array\n\n// SC: O(k)\n```\n---\n##### 2. Using array to mark presence (faster):\n``` java []\nclass Solution {\n    public int similarPairs(String[] words) {\n        int n = words.length, count = 0;\n        int[] a1, a2;\n        Set<Character> set1, set2;\n\n        for (int i = 0; i < n - 1; i++) {\n            a1 = new int[26];\n            for (char c : words[i].toCharArray()) {\n                a1[c - \'a\'] = 1;\n            }\n\n            for (int j = i + 1; j < n; j++) {\n                a2 = new int[26];\n                for (char c : words[j].toCharArray()) {\n                    a2[c - \'a\'] = 1;\n                }\n\n                if (Arrays.equals(a1, a2)) {\n                    count++;\n                }\n            }\n        }\n\n        return count;\n    }\n}\n\n// TC: O(n^2 * k)\n// n is the length of array and k is the length of word in array\n\n// SC: O(1)
['Array', 'Hash Table', 'Java']