FastPrepTop K Most Talkative Chat Users
Problems/Top K Most Talkative Chat Users

Top K Most Talkative Chat Users

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives log lines with a timestamp, username, and text, plus the most talkative user, top-k, and a parse_log helper. Here we count message lines, and we fix the tie order and what happens with bad lines. Our version is about 91% the same as the reported question.

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

Interview reports that mention this question

  • Google L3 New Grad Virtual Onsite: 1 Experience
  • Google PhD AI/ML New Grad Phone Screen: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] topTalkativeUsers(String[] logs, int k) {
        // Write your code here.
    }
}
Checking account…