Question
An emergency department logs a short symptom code (a string such as "C12") for every arriving patient. Given the day's list of codes and an integer k, return the k most common codes, most frequent first. If two codes were logged the same number of times, put the alphabetically smaller code first. Assume k is between 1 and the number of distinct codes. Example: codes = ["C12", "F03", "C12", "A99"], k = 2 gives ["C12", "A99"].
common_symptom_codes(codes: list[str], k: int) → list[str][["C12","F03","C12","A99"],2]out["C12","A99"]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.