Python: Easy Explained: Time = O(n^2) Space = Constant
Idea: For each word count the number of letters together in a hashmap/array.\nE.g.: words = [\'abc\',\'aabc\',\'bc\']\nHashmap = [\'a\' : 3, \'b\': 3, \'c\': 3]
Idea: For each word count the number of letters together in a hashmap/array.\nE.g.: words = [\'abc\',\'aabc\',\'bc\']\nHashmap = [\'a\' : 3, \'b\': 3, \'c\': 3]\n\nNow, if every string in words are made to be equal, tehn count of every letter in hashmap must be divisible by the length of words, otherwise atleast one letter will be extra in one word.\nE.g: words = [\'abcc\',\'aabc\',\'bc\']\nHashmap = [\'a\' : 3, \'b\': 3, \'c\': 4]\nHere, \'abc\' will be present in all the strings but one extra \'c\' will be with atleast one of them, like [\'abcc\',\'abc\',\'abc] or [\'abc\',abcc\',\'abc\'] or [\'abc\',\'abc\',\'abcc\']...\n\nSo, calculate the hashmap and check if any element in hashmap is not exactly divisible by the number of words.\n```\nclass Solution:\n    def makeEqual(self, words: List[str]) -> bool:\n        def indx(x):\n            return ord(x) - ord(\'a\')\n        \n        hashmap = [0]*26\n        for word in words:\n            for c in word:\n                hashmap[indx(c)]+=1\n        \n        n = len(words)\n        \n        for i in range(26):\n            if hashmap[i]%n != 0:\n                return False\n        return True\n```\nTime: O(n) for iterating through each word in words and O(n) for iterating through each character in a word = O(n^2)\nSpace: Constant as we are using a hashmap of fixed size (26).\n\n
['Python']