Daily Question - 30th December 2023
Intuition\nThe intuition of the problem is to be able to distribute all characters equally amongst all the 3 string, for eg in example 1 , string is abc,aabc,bc
# Intuition\nThe intuition of the problem is to be able to distribute all characters equally amongst all the 3 string, for eg in example 1 , string is `abc,aabc,bc` in order `to make all of them equal total number of a\'s, total number of b\'s, and total number of c\'s must all be divisible by the length of vector words`, only then all the characters can be equally distributed in all the strings, and all strings can become equal.\n\n# Approach\n1. Make an `unordered map` to store each `character` and its `count`.\n2. Traverse all the strings in the vector words and calculate `frequency` of each character and `store` it in a `map`.\n3. Traverse the map and check of the `frequency of each character` is `divisible by n`=length of words, i.e.` i.second % n == 0`\n4. If yes, return true else return false.\n\n# Complexity\n- Time complexity: O(n)\n\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    bool makeEqual(vector<string>& words) {\n        unordered_map<char,int>mp;\n        int n=words.size();\n        for(int i=0;i<n;i++)\n        {\n           for(auto j:words[i])\n           {\n               mp[j]++;\n           }\n        }\n        for(auto i:mp)\n        {\n            if(i.second%n!=0)\n            {\n                return false;\n            }\n        }\n        return true;\n    }\n};\n```
['C++']