Code Room
CodingMediumcod-g442
Subject Stream processingLevel Mid–Senior~30 minCommon in Distributed systems · Algorithms & data structures interviewsIndustries Software development, Technology

Question

You consume a stream of string tokens (given as a list) and must report the k most frequent. Return the top-k tokens ordered by descending count; break ties by token ascending (lexicographic). If fewer than k distinct tokens exist, return all of them. k is a positive integer. Return just the list of tokens (not counts).

Implement
top_k_frequent(tokens: list[str], k: int) → list[str]
Examples
in[["a","b","a","c","b","a"],2]out["a","b"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.