Code RoomK most common codes
EasyPrep Room Coding #463

K most common codes

CodingAlgorithms & data structuresEntry–Mid~12 min

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.

0:00 of about 12 min
InputExpectedGot
[["C12","F03","C12","A99"],2]["C12","A99"]not run yetsample