2284. Sender With Largest Word Count
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 58% Topics: Array, Hash Table, String, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n * l)
# Space: O(n)
import collections
import itertools
# freq table
class Solution(object):
def largestWordCount(self, messages, senders):
"""
:type messages: List[str]
:type senders: List[str]
:rtype: str
"""
cnt = collections.Counter()
for m, s in itertools.izip(messages, senders):
cnt[s] += m.count(' ')+1
return max((k for k in cnt.iterkeys()), key=lambda x: (cnt[x], x))
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions