Honor roll by class
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.
0:00 of about 17 min
solution.py
InputExpectedGot
[["math,ava,91","math,raj,88","math,mia,95","art,leo,70"],2]["art,leo,70","math,mia,95","math,ava,91"]not run yetsample