Code Room
CodingHardcod-g437
Subject Data wranglingLevel Senior–Staff~35 minCommon in ML systems interviewsIndustries Software development, Technology

Question

Given `events`, a list of [category, item, score] triples (category/item are strings, score is an int), return the top `k` items per category by total score. For each category, sum scores per item, then keep the k items with the highest totals; break ties by item name ascending. Output a list of [category, item, total] sorted by category ascending, then total descending, then item ascending. If a category has fewer than k distinct items, return all of them.

Implement
top_k_per_category(events: list[list], k: int) → list[list]
Examples
in[[["food","pizza",5],["food","sushi",9],["food","pizza",5],["toys","lego",3]],1]out[["food","pizza",10],["toys","lego",3]]
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.