Beats 100% || Easy To understand || maps || cpp || java || py || js || c# || c
Intuition\nThe idea is to ensure that each character occurs a number of times that is a multiple of the total number of words. This condition is necessary becau
# Intuition\nThe idea is to ensure that each character occurs a number of times that is a multiple of the total number of words. This condition is necessary because characters must be evenly distribute among all the words.\n\nIf this condition is met for every character, it implies that characters can rearrange to make all words equal.\n\n# Approach\nFrequency Counting:\n\nIterate through each word in the list.\nCount the frequency of each character using a data structure (e.g., Counter in Python, Map in C++/Java).\nCheck Frequencies:\n\nAfter counting frequencies, check if the count of each character is divisible by the total number of words. If not, return false.\nReturn Result:\n\nIf all characters have frequencies divisible by the total number of words, return true. This means that it\'s possible to rearrange the characters to make all the words equal.\n\n# Complexity\n- Time complexity:\nO(N*M) where N is the number of words and M is the average length of the words\n\n- Space complexity:\nO(M), where M is the number of unique characters in all words.\n```c++ []\nclass Solution {\npublic:\n    bool makeEqual(vector<string>& words) {\n        int len= words.size();\n        unordered_map<char,int> mp;\n        for(int i=0;i<words.size();i++)\n        {\n            for(auto j: words[i])\n            {\n                mp[j]++;\n            }\n        }\n        for(auto i: mp)\n        {\n            if( i.second % len != 0 )\n            {\n                return false;\n            }\n        }\n        return true;\n    }\n};\n```\n```c []\ntypedef struct {\n    char key;\n    int value;\n} Pair;\n\nbool makeEqual(char** words, int wordsSize) \n{\n    int length = wordsSize;\n    Pair charCount[26]; \n    for (int i = 0; i < 26; i++) \n    {\n        charCount[i].key = \'a\' + i;\n        charCount[i].value = 0;\n    }\n    for (int i = 0; i < wordsSize; i++) \n    {\n        char *word = words[i];\n        int wordLen = strlen(word);\n        for (int j = 0; j < wordLen; j++) \n        {\n            charCount[word[j] - \'a\'].value++;\n        }\n    }\n    for (int i = 0; i < 26; i++) \n    {\n        if (charCount[i].value % length != 0) \n        {\n            return false; \n        }\n    }\n    return true;\n}\n\n```\n```python []\nclass Solution:\n    def makeEqual(self, words):\n        length = len(words)\n        char_count = Counter()\n        \n        for word in words:\n            char_count.update(word)\n        \n        for count in char_count.values():\n            if count % length != 0:\n                return False\n        \n        return True\n\n```\n```java []\nclass Solution {\n    public boolean makeEqual(String[] words) \n    {\n        int length = words.length;\n        Map<Character, Integer> charCount = new HashMap<>();\n        for (String word : words) \n        {\n            for (char c : word.toCharArray())       \n            {\n                charCount.put(c, charCount.getOrDefault(c, 0) + 1);\n            }\n        }\n        for (int count : charCount.values()) \n        {\n            if (count % length != 0) \n            {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n\n```\n```javascript []\nvar makeEqual = function(words) \n{\n    const length = words.length;\n        const charCount = new Map();\n        for (const word of words) \n        {\n            for (const char of word) \n            {\n                charCount.set(char, (charCount.get(char) || 0) + 1);\n            }\n        }\n        for (const count of charCount.values()) \n        {\n            if (count % length !== 0) \n            {\n                return false;\n            }\n        }\n        return true;\n};\n\n```\n```c# []\npublic class Solution \n{\n    public bool MakeEqual(string[] words) \n    {\n        int length = words.Length;\n        Dictionary<char, int> charCount = new Dictionary<char, int>();\n        foreach (var word in words) \n        {\n            foreach (var c in word) \n            {\n                charCount[c] = charCount.GetValueOrDefault(c, 0) + 1;\n            }\n        }\n        foreach (var count in charCount.Values) \n        {\n            if (count % length != 0) \n            {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n\n```\n![WhatsApp Image 2023-10-20 at 08.23.29.jpeg](https://assets.leetcode.com/users/images/04b3ea8f-e0fb-40c1-bdad-6ecb3c137689_1703901502.8440616.jpeg)\n\n
['C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#']