Code Room
CodingMediumcod-g1072
Subject Ml metricsLevel Mid–Senior~20 minCommon in ML systems interviewsIndustries Software development

Question

Given items, a list of [id, score] pairs (id is a string, score is a number), return the ids of the top k items by score, highest first. Break ties between equal scores by the id in ascending lexicographic order. If k exceeds the number of items, return all of them in ranked order. k >= 0. Return the list of ids.

Implement
top_k(items: list[list], k: int) → list[str]
Examples
in[[["a",3],["b",5],["c",1]],2]out["b","a"]
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.