Top K Most Talkative Chat Users
Updated
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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Top K Keys from JSON RecordsCapital One · ONSITE INTERVIEWCapital One interview questions
- Time-Aware Search AutocompleteRoblox · PHONE SCREENRoblox interview questions
- Top N Frequent Words in a FileMeta · PHONE SCREENMeta interview questions
- Sort Characters by How Often They AppearAdobe · PHONE SCREENAdobe interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Top K Frequent WordsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions