High Five - Problem
High Five - Calculate Top Five Average Scores
You're given a list of student test scores where each entry contains a
Input:
Output: Array of pairs
Important: Use integer division when calculating the average of the top 5 scores.
Example: If student 1 has scores [100, 90, 90, 90, 90, 80, 70], their top 5 scores are [100, 90, 90, 90, 90], so the average is (100+90+90+90+90)//5 = 92.
You're given a list of student test scores where each entry contains a
student ID and their score. Your task is to calculate each student's top five average - the average of their five highest scores.Input:
items[i] = [IDi, scorei] representing one score from student with IDiOutput: Array of pairs
[IDj, topFiveAveragej] sorted by student ID in increasing orderImportant: Use integer division when calculating the average of the top 5 scores.
Example: If student 1 has scores [100, 90, 90, 90, 90, 80, 70], their top 5 scores are [100, 90, 90, 90, 90], so the average is (100+90+90+90+90)//5 = 92.
Input & Output
example_1.py โ Basic case with multiple students
$
Input:
items = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]
โบ
Output:
[[1,87],[2,88]]
๐ก Note:
Student 1 has scores [91,92,60,65,87,100]. Top 5 are [100,92,91,87,65]. Average = (100+92+91+87+65)//5 = 435//5 = 87. Student 2 has scores [93,97,77,100,76]. Top 5 are [100,97,93,77,76]. Average = (100+97+93+77+76)//5 = 443//5 = 88.
example_2.py โ Single student case
$
Input:
items = [[1,100],[1,90],[1,90],[1,90],[1,90],[1,80],[1,70]]
โบ
Output:
[[1,92]]
๐ก Note:
Student 1 has scores [100,90,90,90,90,80,70]. The top 5 scores are [100,90,90,90,90]. Average = (100+90+90+90+90)//5 = 460//5 = 92.
example_3.py โ Edge case with exactly 5 scores
$
Input:
items = [[1,85],[2,90],[1,88],[2,85],[1,92],[2,88],[1,95],[2,92],[1,90],[2,95]]
โบ
Output:
[[1,90],[2,90]]
๐ก Note:
Student 1: scores [85,88,92,95,90], all are top 5. Average = (85+88+92+95+90)//5 = 450//5 = 90. Student 2: scores [90,85,88,92,95], all are top 5. Average = (90+85+88+92+95)//5 = 450//5 = 90.
Constraints
- 1 โค items.length โค 1000
- items[i].length == 2
- 1 โค IDi โค 1000
- 0 โค scorei โค 100
- Each student has at least 5 scores
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code