Top K Most Talkative Chat Users
Problem statement
Each chat-log line has the form timestamp username message text, separated by ASCII spaces. The timestamp and username are the first two tokens; the remaining text may contain spaces.
A user's talkativeness is their number of log lines. Return up to k usernames ordered by decreasing message count, breaking ties by lexicographically smaller username.
Malformed lines with fewer than three tokens are ignored.
Function
topTalkativeUsers(logs: String[], k: int) → String[]Examples
Example 1
logs = ["1 alice hi","2 bob hello","3 alice again"]k = 2return = ["alice","bob"]Alice has two messages and Bob has one.
Example 2
logs = ["1 z x","2 a y"]k = 1return = ["a"]The counts tie, so a wins lexicographically.
Example 3
logs = []k = 5return = []No log lines produce no users.
Constraints
0 <= logs.length <= 200000.0 <= k <= 100000.- Valid timestamps and usernames contain no spaces.