Skip to content

Commit c084bb2

Browse files
authored
Create sender-with-largest-word-count.cpp
1 parent ad1a681 commit c084bb2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: O(n * l)
2+
// Space: O(n)
3+
4+
// freq table
5+
class Solution {
6+
public:
7+
string largestWordCount(vector<string>& messages, vector<string>& senders) {
8+
unordered_map<string, int> cnt;
9+
string result;
10+
int mx = 0;
11+
for (int i = 0; i < size(messages); ++i) {
12+
cnt[senders[i]] += count(begin(messages[i]), end(messages[i]), ' ') + 1;
13+
if (cnt[senders[i]] > mx || (cnt[senders[i]] == mx && senders[i] > result)) {
14+
mx = cnt[senders[i]];
15+
result = senders[i];
16+
}
17+
}
18+
return result;
19+
}
20+
};

0 commit comments

Comments
 (0)