Ctrl K

Most Talkative Sender

Medium
You get a group chat log: texts[i] is the text of the i-th message and authors[i] is the name of the person who sent it. The same person may have sent several messages. A message is a list of words separated by exactly one space, with no leading or trailing spaces. An author's word count is the total number of words across all of their messages. Return the name of the author with the highest word count. On a tie, return the lexicographically greatest name. Names compare character by character: every uppercase English letter is smaller than every lowercase one, and "Bob" and "bob" are different authors.
Example 1
texts=["see you at noon", "ok", "running late sorry", "fine"], authors=["mira", "Tom", "Tom", "mira"] → 'mira'

mira wrote 4 + 1 = 5 words and Tom wrote 1 + 3 = 4, so mira wins.

Example 2
texts=["hello there", "good night"], authors=["Zoe", "adam"] → 'adam'

Both wrote 2 words. Lowercase letters sort after uppercase ones, so "adam" is greater than "Zoe".

Constraints
  • 1 ≤ len(texts) = len(authors) ≤ 10⁵
  • 1 ≤ len(texts[i]) ≤ 100; a message is English letters with single spaces between words
  • 1 ≤ len(authors[i]) ≤ 10; a name consists of English letters only
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMost Searched Words MediumDomain Visit Rollup MediumRanking Finalists by Jury Ballots MediumTwo Pieces Glued Into a Code MediumPalindrome From Two-Letter Cards Medium
loading Python…
Input
texts=["see you at noon", "ok", "running late sorry", "fine"], authors=["mira", "Tom", "Tom", "mira"]
Expected
'mira'

Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.