Best student finder

Table 1 contains student IDs and scores for Programming, Probability, and Calculus. The final two rows illustrate the information that the function must determine for every subject.

Table 1: Matrix of student scores in different subjects.
Student ID / output Programming Probability Calculus
s01 85 75 90
s02 70 80 85
s03 75 70 80
Best grade
Best student

To analyze student performance and help select next year’s teaching assistants, develop a function named find_best_students_per_subject. It must take a list in which each item contains a student ID and a list of subject scores. Use while loops to determine the best grade and student for each subject, and return one (best_grade, student_id) tuple per subject, in the original subject order. If students tie, return the first one in the input list.

Assume the input contains at least one student and at least one subject. Every student has the same number of integer scores, with subject positions in the same order. Leave the input and its score lists unchanged.

Present your algorithm in Python, pseudocode, or a flowchart using while loops. The Python starter in Listing 1 preserves the supplied scores and checks the required result. Add a check for a tie.

For example, in Table 1, the best Programming grade is 85 and the student who obtained it is s01. Therefore, the first returned tuple must be (85, "s01").

Listing 1: Starter function and supplied checks for finding the best student in each subject.
def find_best_students_per_subject(
    student_scores: list[tuple[str, list[int]]],
) -> list[tuple[int, str]]:
    # Add code here!
    pass


scores = [
    ("s01", [85, 75, 90]),
    ("s02", [70, 80, 85]),
    ("s03", [75, 70, 80]),
]

assert find_best_students_per_subject(scores) == [
    (85, "s01"),
    (80, "s02"),
    (90, "s01"),
]