#2284

Sender With Largest Word Count

specialist · 725 · lc medium +31 · verified · 59.6% accepted · 466 likes · top 57%

Description

You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] was sent by senders[i].

Each message is a space-separated sequence of words with no leading or trailing spaces. A sender's total word count is the sum of word counts across all their messages.

Return the sender with the highest total word count. Break ties by returning the lexicographically largest name.

Note:

- Uppercase letters precede lowercase letters in lexicographic order.

- "Alice" and "alice" are different names.

Example 1:

Input: messages = ["Hello userTwooo","Hi userThree","Wonderful day Alice","Nice day userThree"], senders = ["Alice","userTwo","userThree","Alice"]
Output: "Alice"
Explanation: Alice sends a total of 2 + 3 = 5 words.
userTwo sends a total of 2 words.
userThree sends a total of 3 words.
Since Alice has the largest word count, we return "Alice".

Example 2:

Input: messages = ["How is leetcode for everyone","Leetcode is useful for practice"], senders = ["Bob","Charlie"]
Output: "Charlie"
Explanation: Bob sends a total of 5 words.
Charlie sends a total of 5 words.
Since there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie.

Code

1
2
3