✅Beats 100% Users - C++, JAVA, Python, JavaScript || With explanation ||
\n\n# Approach\n Describe your approach to solving the problem. \n1. Character Counting:\n   - The code uses a hashmap to count the frequency of each character 
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**1. Character Counting:**\n   - The code uses a hashmap to count the frequency of each character in all words.\n\n**2. Efficient Counting:**\n   - It leverages an `unordered_map` for efficient character lookup and frequency updates.\n\n**3. Divisibility Check:**\n   - It iterates through the hashmap to check if the count of each character is divisible by the number of words.\n   - If any character\'s count isn\'t divisible, it\'s impossible to make all words equal.\n\n**4. Return Boolean Result:**\n   - The function returns `true` if all character counts are divisible, indicating equal distribution is possible, and `false` otherwise.\n\n**Time Complexity:**\n   - O(N), where N is the total number of characters in all words.\n     - Iterating through words and characters takes O(N) time.\n     - Hashmap operations have an average-case time complexity of O(1).\n\n**Space Complexity:**\n   - O(C), where C is the number of distinct characters in the input words.\n     - The hashmap stores character counts, using space proportional to the number of distinct characters.\n\n# Code\n\n```C++ []\nclass Solution {\npublic:\n    bool makeEqual(vector<string>& words) {\n        unordered_map<char,int> mp;\n        int n=words.size();\n        for(auto s:words){\n            for(auto c:s){\n                mp[c]++;\n            }\n        }\n        for(auto i:mp){\n            if(i.second%n) return false;\n        }\n        return true;\n    }\n};\n```\n\n```JAVA []\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\nclass Solution {\n    public boolean makeEqual(List<String> words) {\n        Map<Character, Integer> charCount = new HashMap<>();\n        int numWords = words.size();\n\n        for (String word : words) {\n            for (char c : word.toCharArray()) {\n                charCount.put(c, charCount.getOrDefault(c, 0) + 1);\n            }\n        }\n\n        for (int count : charCount.values()) {\n            if (count % numWords != 0) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n}\n\n```\n\n```python []\nclass Solution:\n    def makeEqual(self, words: List[str]) -> bool:\n        charCount = {}\n        numWords = len(words)\n\n        for word in words:\n            for char in word:\n                charCount[char] = charCount.get(char, 0) + 1\n\n        for count in charCount.values():\n            if count % numWords != 0:\n                return False\n\n        return True\n\n```\n```javascript []\nclass Solution {\n    makeEqual(words) {\n        const charCount = {};\n        const numWords = words.length;\n\n        for (const word of words) {\n            for (const char of word) {\n                charCount[char] = (charCount[char] || 0) + 1;\n            }\n        }\n\n        for (const count of Object.values(charCount)) {\n            if (count % numWords !== 0) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n}\n\n```\n\n
['Hash Table', 'String', 'Counting', 'Python', 'C++', 'Java', 'JavaScript']