Easy explanation✅|| Beat 100% || Counting
Intuition\nIts a very easy problem. just consider all the strings as one string, and check if we can divide it into n equal strings. we do not have any limitati
# Intuition\nIts a very easy problem. just consider all the strings as one string, and check if we can divide it into n equal strings. we do not have any limitation to the moves.\n\ne.g., words = ["abcb", "aabc", "bcbb"] \ntake it as one string abc + aabc + bc = abcbaabcbcbb\ncalculate the frequency of characters, 3 a\'s, 6 b\'s and 3 c\'s\n\nwe can put 1a, 2b and 1c (aabc) in each n strings to make them equal.\n\n# Approach\n**A frequency array** Make a frequency array of size 26, to store the frequceny of each character in the words.\n\n**Check** use a for loop on frequency array to check if we can divide the character into n words evenly.\ne.g., f[i] = 6, \nif n == 3 => 6 % 3 == 0, we can divide on the other side if n == 4 => 6 % 4 == 2, we can not evenly distribute the characters.\n\n# Complexity\n- Time complexity:\n$$O(words.length * word.length + 26)$$\n\n- Space complexity:\n$$O(26)$$ due to frequencey array.\n# Code\n```java []\nclass Solution {\n    public boolean makeEqual(String[] words) {\n        int n = words.length;\n        int f[] = new int[26];\n// store the frequency of each character.\n        for(String word: words) {\n            for(char c: word.toCharArray()) f[c - \'a\']++;\n        }\n// check if we can divide the character into n strings evenly on not.\n        for(int x: f) if(x % n != 0) return false;\n        return true;\n    }\n}\n```\n```cpp []\nclass Solution {\npublic:\n    bool makeEqual(std::vector<std::string>& words) {\n        int n = words.size();\n        std::vector<int> f(26, 0);\n// store the frequency of each character\n        for (const std::string& word : words) {\n            for (char c : word) {\n                f[c - \'a\']++;\n            }\n        }\n// check if we can divide the character into n strings evenly on not.\n\n        for (int x : f) {\n            if (x % n != 0) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n};\n```\n```python []\nclass Solution:\n    def makeEqual(self, words: List[str]) -> bool:\n        n = len(words)\n        f = [0] * 26\n// store the frequency of each character\n        for word in words:\n            for c in word:\n                f[ord(c) - ord(\'a\')] += 1\n// check if we can divide the character into n strings evenly on not.\n\n        for x in f:\n            if x % n != 0:\n                return False\n\n        return True\n```\n
['Counting', 'Python', 'C++', 'Java', 'Python3']