Skip to content

Commit d30d4ea

Browse files
authored
Create sender-with-largest-word-count.py
1 parent c084bb2 commit d30d4ea

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n * l)
2+
# Space: O(n)
3+
4+
import collections
5+
import itertools
6+
7+
8+
# freq table
9+
class Solution(object):
10+
def largestWordCount(self, messages, senders):
11+
"""
12+
:type messages: List[str]
13+
:type senders: List[str]
14+
:rtype: str
15+
"""
16+
cnt = collections.Counter()
17+
for m, s in itertools.izip(messages, senders):
18+
cnt[s] += m.count(' ')+1
19+
return max((k for k in cnt.iterkeys()), key=lambda x: (cnt[x], x))

0 commit comments

Comments
 (0)