Citadel OA Interview Question: Best Average Grade | Hash Map and Average Score Calculation

18 Views
No Comments

Best Average Grade

Implement the function best_average_grade(exam_grades: List[Tuple[str, int]]) -> Tuple[str, float].

Given a list of students and their exam grades, return the best student and their average grade.

If multiple students have the same highest average grade, return the student whose name comes first in alphabetical order.

Examples

Input: [("Bob", 85), ("Sara", 92), ("Bob", 90), ("Sara", 95)]
Output: ("Sara", 93.5)
Input: [("Jim", 85), ("Sam", 88)]
Output: ("Sam", 88)

This problem asks you to aggregate exam scores by student name, compute each student's average grade, and return the student with the highest average. A hash map is the natural fit: store total score and count for each name, then compute averages in a final pass. If multiple students tie for the best average, choose the alphabetically smallest name.

END
 0