Python 99.90 memory efficient - Simple | Fast | Detailed Explanation
Take a defaultdict of integers to store the count of words.\n Iterate over the senders array and count number of words during each iteration. If key already exi
* Take a `defaultdict` of integers to store the count of words.\n* Iterate over the `senders` array and count number of words during each iteration. If key already exisits in the hash table, add the current value in already exisiting value. For example, if `Alice` has send a message `Hi`. Add it to the dictionary with value as 1. If again, `Alice` sends out a message, for instance `Hello` then update the value this time. Now Alice will have `value = 2`.\n* Now after iterating through the array, you will have a hashtable ready with the senders and their number of words. \n* At this point, we only need to calculate the sender with max words. \n* Initialize a `max_` variable with value **0**, and `winner` with value equal to first index `senders[0]`\n* We need to take care of the case when their is a tie between two senders. \n* Python `max` function gives you the value in lexicographical order in case of strings. \n* return the `winner` in the end. \n\n```\nclass Solution:\n    def largestWordCount(self, messages: List[str], senders: List[str]) -> str:\n        d = defaultdict(int)\n        for i in range(len(senders)):\n            d[senders[i]] = d.get(senders[i], 0) + len(messages[i].split())\n\n        max_ = 0\n        winner = senders[0]\n        for key, value in d.items():\n            if value == max_:\n                winner = max(winner, key)\n            if value > max_:\n                winner = key\n                max_ = value\n\n        return winner\n```\n\nDo comment if you have any doubt, feel free to reach out. \nIf you like the solution, please do upvote. Thanks.
['String']