Practice/Google/Leetcode 2284. Sender With Largest Word Count
CodingMust
You are analyzing message data from a chat platform. Given two arrays of equal length — one containing message texts and another containing the corresponding sender names — determine which sender has contributed the most words across all their messages.
A word is defined as any sequence of non-space characters. For example, "hello world" contains 2 words.
If multiple senders have the same highest word count, return the sender whose name is lexicographically largest when compared case-sensitively (meaning 'Z' comes before 'a' in standard ASCII ordering).
Example 1:
Input: messages = ["Hello world", "Hi there friend", "Goodbye"] senders = ["Alice", "Bob", "Alice"] Output: "Bob" Explanation: Alice's total is 2 + 1 = 3 words. Bob's total is 3 words. Since they're tied, we compare "Alice" and "Bob" lexicographically. "Bob" > "Alice", so Bob wins.
Example 2:
Input: messages = ["Good morning", "See you later", "Thanks"] senders = ["Tom", "Jerry", "Tom"] Output: "Tom" Explanation: Tom sent 2 + 1 = 3 words. Jerry sent 3 words. They're tied, but "Tom" > "Jerry" lexicographically, so Tom wins.
Example 3:
Input: messages = ["a b c d e", "f"] senders = ["User", "Admin"] Output: "User" Explanation: User sent 5 words, Admin sent 1 word. User has more words.