516. High Five
Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calculate each student's top five average.
Return the answer as an array of pairs result, where result[j] = [IDj, topFiveAveragej] represents the student with IDj and their top five average. Sort result by IDj in increasing order.
A student's top five average is calculated by taking the sum of their top five scores and dividing it by 5 using integer division.
Example 1:
Input: items = [[3,95],[3,90],[1,85],[2,80],[1,70],[2,75],[3,100],[1,60],[2,85],[1,90], [3,85],[2,78],[1,77],[3,88],[2,79]]
Output: [[1,77],[2,79],[3,91]]
Explanation:
Student 1: Scores → 85, 70, 60, 90, 77 → Top five avg = (90 + 85 + 77 + 70 + 60) / 5 = 77
Student 2: Scores → 80, 75, 85, 78, 79 → Top five avg = (85 + 80 + 79 + 78 + 75) / 5 = 79
Student 3: Scores → 95, 90, 100, 85, 88 → Top five avg = (100 + 95 + 90 + 88 + 85) / 5 = 91
Example 2:
Input: items = [[5,100],[5,98],[5,99],[5,97],[5,96],[5,95]]
Output: [[5,98]]
Explanation:
Student 5: Scores → 100, 98, 99, 97, 96, 95
Top five avg = (100 + 99 + 98 + 97 + 96) / 5 = 98
Now Your Turn!
Pick the correct output for the given inputInput: items = [[10,88],[10,85],[10,90],[10,95],[10,80],[10,75],[10,70]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= items.length <= 1000
- items[i].length == 2
- 1 <= IDi <= 1000
- 0 <= scorei <= 100
- For each IDi, there will be at least five scores.