java.lang.Object
g2201_2300.s2284_sender_with_largest_word_count.Solution

public class Solution extends Object
2284 - Sender With Largest Word Count.<p>Medium</p> <p>You have a chat log of <code>n</code> messages. You are given two string arrays <code>messages</code> and <code>senders</code> where <code>messages[i]</code> is a <strong>message</strong> sent by <code>senders[i]</code>.</p> <p>A <strong>message</strong> is list of <strong>words</strong> that are separated by a single space with no leading or trailing spaces. The <strong>word count</strong> of a sender is the total number of <strong>words</strong> sent by the sender. Note that a sender may send more than one message.</p> <p>Return <em>the sender with the <strong>largest</strong> word count</em>. If there is more than one sender with the largest word count, return <em>the one with the <strong>lexicographically largest</strong> name</em>.</p> <p><strong>Note:</strong></p> <ul> <li>Uppercase letters come before lowercase letters in lexicographical order.</li> <li><code>&quot;Alice&quot;</code> and <code>&quot;alice&quot;</code> are distinct.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> messages = [&ldquo;Hello userTwooo&rdquo;,&ldquo;Hi userThree&rdquo;,&ldquo;Wonderful day Alice&rdquo;,&ldquo;Nice day userThree&rdquo;], senders = [&ldquo;Alice&rdquo;,&ldquo;userTwo&rdquo;,&ldquo;userThree&rdquo;,&ldquo;Alice&rdquo;]</p> <p><strong>Output:</strong> &ldquo;Alice&rdquo;</p> <p><strong>Explanation:</strong> Alice sends a total of 2 + 3 = 5 words.</p> <p>userTwo sends a total of 2 words.</p> <p>userThree sends a total of 3 words.</p> <p>Since Alice has the largest word count, we return &ldquo;Alice&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> messages = [&ldquo;How is leetcode for everyone&rdquo;,&ldquo;Leetcode is useful for practice&rdquo;], senders = [&ldquo;Bob&rdquo;,&ldquo;Charlie&rdquo;]</p> <p><strong>Output:</strong> &ldquo;Charlie&rdquo;</p> <p><strong>Explanation:</strong> Bob sends a total of 5 words.</p> <p>Charlie sends a total of 5 words.</p> <p>Since there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == messages.length == senders.length</code></li> <li><code>1 <= n <= 10<sup>4</sup></code></li> <li><code>1 <= messages[i].length <= 100</code></li> <li><code>1 <= senders[i].length <= 10</code></li> <li><code>messages[i]</code> consists of uppercase and lowercase English letters and <code>' '</code>.</li> <li>All the words in <code>messages[i]</code> are separated by <strong>a single space</strong>.</li> <li><code>messages[i]</code> does not have leading or trailing spaces.</li> <li><code>senders[i]</code> consists of uppercase and lowercase English letters only.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • largestWordCount

      public String largestWordCount(String[] messages, String[] senders)