Ctrl K

Average of the Best Five

Easy
You have a log of player results: scores[i] = [id, score] means the player with number id once scored score points. Every player appears in the log at least five times, and records come in no particular order. For each player, take their five best results, add them up and divide by 5 using integer division (drop the fraction). Return a list of [id, average] pairs, one per player, sorted by id in increasing order.
Example 1
scores=[[2, 70], [4, 100], [2, 80], [4, 90], [2, 90], [4, 80], [2, 60], [4, 70], [2, 100], [4, 60], [2, 50]] → [[2, 80], [4, 80]]

Player 2 has six results; the best five are 100 + 90 + 80 + 70 + 60 = 400, and 400 // 5 = 80. Player 4 has exactly five: (100 + 90 + 80 + 70 + 60) // 5 = 80.

Example 2
scores=[[9, 41], [9, 40], [9, 40], [9, 40], [9, 40]] → [[9, 40]]

The sum is 201, and integer division by 5 gives 40: the fraction is dropped.

Constraints
  • 1 ≤ len(scores) ≤ 1000
  • scores[i] is a pair [id, score]
  • 1 ≤ id ≤ 1000
  • 0 ≤ score ≤ 100
  • Every player has at least five records
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBest Picks in Order EasyClearing the Stacks Evenly EasyMost Common Values MediumJobs With a Cooldown MediumNarrowest Range Touching Every List Hard
loading Python…
Input
scores=[[2, 70], [4, 100], [2, 80], [4, 90], [2, 90], [4, 80], [2, 60], [4, 70], [2, 100], [4, 60], [2, 50]]
Expected
[[2, 80], [4, 80]]

Run checks the first 3 tests in your browser. Submit checks all 74 tests on the server, hidden ones included.