Chat Top Talkers
GooglePhone screenMedium
A chat room transcript is a list of text lines. A message line has the form HH:MM <name> text: two digits, a colon, two digits, a space, the sender's name in angle brackets, and then either nothing or a space followed by the message text. Names use letters, digits and _, and are case-sensitive. Any other line (a join notice, a blank line, a malformed line) is not a message and is ignored. A message's word count is the number of whitespace-separated words in its text, so an empty text counts 0 words.
Part 1: Most words
Given the transcript log and an integer n, return the n users with the most total words across all their messages, as [name, words] pairs. Order the pairs by words from highest to lowest, breaking ties by name in ascending string order. If there are fewer than n users, return them all.
- Example 1
- n
2- log
["10:00 <alice> Hi! What's up?","10:01 <bob> Hey","10:02 * carol joined the room","10:03 <alice> Dinner tonight?","10:04 <carol> I'm down, but only if it isn't vegan","10:05 <bob> Fine by me"]- Output
[["carol",8],["alice",5]]
Why: alice wrote 3 + 2 = 5 words, bob 1 + 3 = 4, and carol 8. The join notice is not a message and adds nothing, so the top two are carol (8) then alice (5).
Constraints
0 <= len(log) <= 10^51 <= len(log[i]) <= 2001 <= n <= 10^5