Code Room
CodingEasycod-g1279
Subject HeapsLevel Entry–Mid~12 minCommon in Algorithms & data structures interviewsIndustries Software development

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"].

Implement
common_symptom_codes(codes: list[str], k: int) → list[str]
Examples
in[["C12","F03","C12","A99"],2]out["C12","A99"]
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.