Trains the technique from
LeetCode 1086High FiveThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A workshop logs one entry per weld inspection. Entry records[i] = [badge, score] says that the apprentice wearing badge scored score on one inspection. An apprentice may appear many times, and the entries are in no particular order.
For every badge that appears, take that apprentice's five highest scores and average them, rounding the average down to a whole number. Repeated scores count separately, so an apprentice with five inspections all scored 80 has five scores of 80.
Return one entry [badge, average] per badge that appears, ordered by badge from smallest to largest.
Example 1
Badge 7 has exactly five scores, adding to 499. Dividing by five and rounding down gives 99.
Example 2
The score of 40 is not among the badge's five highest, so the average is taken over 90, 80, 70, 60 and 50, which add to 350.
Example 3
Badge 3 averages 100 and badge 1000 averages 0. Badge 3 is listed first because the answer is ordered by badge, not by where the entries appear in the log.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def top_five_averages(records: list[list[int]]) -> list[list[int]]:public int[][] topFiveAverages(int[][] records)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.