Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Highest Scoring Student

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Highest Scoring Student. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Dropbox Paper may need to identify the highest-scoring student in a grading workflow. Implement a GradeBook class with two methods, then write a function that returns the student with the highest average score.

  1. add_score(student, score) records one integer score for a student.
  2. average_score(student) returns that student's average as a number.
  3. highest_scoring_student(records) accepts all grade records, uses the gradebook, and returns the student whose average is greatest. If multiple students have the same average, return the lexicographically smallest student name. Return None when records is empty.

Formal Specification

  • records is a list of two-element records, where each record is [student: str, score: int].
  • Scores are integers from 0 through 100.
  • The function returns a string student name, or None for an empty input.
  • Every student in a non-empty input has at least one score.

Constraints

  • 0 <= records.length <= 10^5
  • 1 <= student.length <= 50
  • 0 <= score <= 100
  • Student names contain printable letters only
  • Every student in a non-empty input has at least one score

Function Signature

def highest_scoring_student(records):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output