Code Room
CodingMediumcod-g1215
Subject Data wranglingLevel Entry–Mid~17 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A school posts an honor roll per class. Each gradebook row is "class,student,score" (score a non-negative integer; one row per student per class). Given the rows and an integer n >= 1, return up to n rows per class, formatted exactly like the input: classes in ascending name order, and within a class students by score descending, ties broken by name ascending. Example: rows ["math,ava,91", "math,raj,88", "math,mia,95", "art,leo,70"] with n=2 give ["art,leo,70", "math,mia,95", "math,ava,91"].

Implement
honor_roll(rows: list[str], n: int) → list[str]
Examples
in[["math,ava,91","math,raj,88","math,mia,95","art,leo,70"],2]out["art,leo,70","math,mia,95","math,ava,91"]
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.