Average Each Student's Five Highest Scores

Quick Overview

Average Each Student's Five Highest Scores. Each pair in items contains a student ID and one score. For every student, sum their five highest scores and divide by5 using integer division.

Average Each Student's Five Highest Scores

Company: Goldman Sachs

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Each pair in items contains a student ID and one score. For every student, sum their five highest scores and divide by 5 using integer division. Return pairs of ID and this average, ordered by increasing ID. ```cpp class Solution { public: vector<vector<int>> highFive(vector<vector<int>>& items); }; ``` ### Examples **Example 1:** ```text Input: items = [[2,10],[2,20],[2,30],[2,40],[2,50],[2,60]] Output: [[2,40]] Explanation: The top five sum to200, so the integer average is40. ``` **Example 2:** ```text Input: items = [[3,100],[1,50],[3,100],[1,50],[3,100],[1,50],[3,100],[1,50],[3,100],[1,50]] Output: [[1,50],[3,100]] Explanation: Each student has exactly five scores, and IDs are returned in increasing order. ``` ### Constraints - The input has 1 to 1000 pairs; every pair has two entries. - Student IDs are integers in `[1,1000]` and scores in `[0,100]`. - Each represented student has at least five scores. ### Contract considerations Every represented ID has at least five scores. Results must be sorted by ID, not average. ```hint Read the boundary condition Does each average use every recorded score or exactly five, and how should a nonintegral average be returned? ``` ### Boundary reminders Every represented ID has at least five scores. Results must be sorted by ID, not average.

Overview: Average Each Student's Five Highest Scores. Each pair in items contains a student ID and one score. For every student, sum their five highest scores and divide by5 using integer division.

Goldman Sachs logo
Goldman Sachs
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Each pair in items contains a student ID and one score. For every student, sum their five highest scores and divide by 5 using integer division. Return pairs of ID and this average, ordered by increasing ID.

class Solution {
public:
    vector<vector<int>> highFive(vector<vector<int>>& items);
};

Examples

Example 1:

Input: items = [[2,10],[2,20],[2,30],[2,40],[2,50],[2,60]]
Output: [[2,40]]
Explanation: The top five sum to200, so the integer average is40.

Example 2:

Input: items = [[3,100],[1,50],[3,100],[1,50],[3,100],[1,50],[3,100],[1,50],[3,100],[1,50]]
Output: [[1,50],[3,100]]
Explanation: Each student has exactly five scores, and IDs are returned in increasing order.

Constraints

  • The input has 1 to 1000 pairs; every pair has two entries.
  • Student IDs are integers in [1,1000] and scores in [0,100] .
  • Each represented student has at least five scores.

Contract considerations

Every represented ID has at least five scores. Results must be sorted by ID, not average.

Boundary reminders

Every represented ID has at least five scores. Results must be sorted by ID, not average.