Easy to Understand | Beginner Friendly | My Notes
Keep a hashmap that stores keys as elements from sender and the value as a list with the indexes.\n\nIf Senders are [Alice,Zhund,Zhund,Alice]\n\nYour dictionary
Keep a hashmap that stores keys as elements from sender and the value as a list with the indexes.\n\nIf Senders are [Alice,Zhund,Zhund,Alice]\n\nYour dictionary becomes: {\'Alice\': [0,3], \'Zhund\':[1,2]}\n\nNow you need to iterate within this dictionary.\nAnd use those indexes.\n\nSo, for every element, we can iterate in the list of indexes it has.\n\n*len(messages[each].split(\' \'))* will give you the word count for the index stored in the messages.\nand then you can compare the total count with the maximum count everytime.\n\n\n```\nans = \'\'\nd = {}\nfor i in range(0,len(senders)):\n\td.setdefault(senders[i], []).append(i)\n\nfor element in d.keys():\n\tcount = 0\n\tfor each in d[element]:\n\t\tcount+=len(messages[each].split(\' \'))\n\t\t#equal case\n\t\tif count == mc and element>ans:\n\t\t\tans = element\n\t\t#greater case\n\t\tif count>mc:\n\t\t\tmc = count\n\t\t\tans = element\n\nreturn ans\n```\n\n\nNote:\n\n[If these notes are helpful, do upvote! I also post the explanation on my channel. The link\ncan be found in my profile as website. If you feel my explanation needs to be improved either while writing here/explaning, feel free to comment.\n]
['Python']