Average Grades per Student
Reported by candidates from Hartford Financial Services's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Hartford Financial Services OA reported in August 2026 is a gentle one, and that's exactly why it bites. Average Grades per Student looks like a warm-up: two parallel arrays, sum each list, divide by its length. The mistake that sinks a first attempt is integer division, which quietly turns 263/3 into 87 and fails the tolerance check. If you're taking this in the next day or two, read the trick below. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you probably won't need it here.
The problem
You are given two parallel arrays, names and grades. Student names[i] has the integer subject grades in grades[i]. Compute the arithmetic average grade for every student: the sum of that student's grades divided by the number of grades. The result is a mapping from each student name to that student's average. Return this mapping as an array averages, where averages[i] is the value associated with names[i]. Preserve the input order; do not sort students or combine grade lists. For example, pairing names[i] with averages[i] reconstructs the name-to-average dictionary. Return the numerical averages without rounding them to integers or a fixed number of decimal places. Each result is accepted when its relative or absolute error is at most 10^-6. Function averageGrades(names: String[], grades: int[][]) → double[] Examples Example 1 names = ["Alice","Bob","Charlie"] grades = [[85,90,88],[70,75,80],[65,70,75]] return = [87.66666666666667,75,70] Alice's grades sum to 263, so her average is 263 / 3. Bob's average is 225 / 3 = 75, and Charlie's is 210 / 3 = 70. The returned values correspond to Alice, Bob, and Charlie in that order. Example 2 names = ["Zoe","Amy"] grades = [[0,100],[20,40,80]] return = [50,46.666666666666664] Zoe has average 100 / 2 = 50, and Amy has average 140 / 3. The grade lists have different lengths. Preserve the input order even though Amy comes first alphabetically. Example 3 names = ["Solo"] grades = [[0]] return = [0] A student with one grade has that grade as the average, including when the grade is 0. Constraints 1 <= names.length = grades.length <= 500. Every name is a nonempty string of at most 50 characters, and all names are distinct. Names are case-sensitive. Every grades[i] contains at least one integer. 0 <= grades[i][j] <= 100. The total number of grades across all students is at most 5000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
This is a plain array pass. For each index i, sum grades[i], divide by grades[i].length, and write the result to averages[i]. The trick is the type. In Java, C++ or similar languages, sum and length are both ints, so the division truncates. Cast the sum to double first, or accumulate into a double. The second pitfall is reordering. The problem says preserve input order, so don't build a hash map and iterate it, and don't sort by name. Example 2 tests this with Zoe before Amy. Don't round either. Return raw doubles, since 10^-6 error is accepted. Constraints are tiny (5000 grades total), so O(total grades) is far more than fast enough. Empty lists can't happen, so division by zero isn't a concern. If you freeze on the casting detail live, StealthCoder is the hedge, but the whole solution is a few lines.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Average Grades per Student cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Hartford Financial Services's OA.
Hartford Financial Services reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Average Grades per Student FAQ
How hard is Average Grades per Student really?+
Easy. It's a single loop over an array of arrays with a sum and a division. The only real way to fail is integer division or reordering the output. Hartford Financial Services reported it in August 2026, and the difficulty is closer to a warm-up than a puzzle.
What's the trick in this problem?+
Force floating-point division. Cast the sum to double before dividing by the count, or accumulate the sum in a double. Otherwise 263/3 becomes 87 instead of 87.666..., and the checker rejects it. Everything else is a straightforward nested loop.
Do I need a hash map since the problem mentions a name-to-average mapping?+
No. The output is an array aligned by index with names. Averages[i] belongs to names[i]. A map adds nothing, and iterating it could scramble the order. Just compute in place and keep the input order.
Should I round the averages?+
No. Return the raw double. The problem accepts relative or absolute error up to 10^-6, so rounding to an integer or fixed decimals can push you out of tolerance. Example 1 expects 87.66666666666667, not 87.67.
How do I prepare for this in 48 hours?+
Skip deep prep on this one. Write the loop once in your language and confirm your division returns a double. Then spend the time on harder array and hash map problems, since an OA usually pairs an easy question with a tougher one.