Top k items by score
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.
0:00 of about 20 min
solution.py
InputExpectedGot
[[["a",3],["b",5],["c",1]],2]["b","a"]not run yetsample