110. Highest Average Student Score

Asked in

Highest Average Score
Given a list of student score entries, find the student with the highest average score.

Each element in marks is a single string in the format studentName,score, where:
  • the part before the comma is the student name
  • the part after the comma is the score as a string
A student may appear multiple times, meaning that student has multiple scores.

Return the name of the student whose average score is the highest.

Important details:
  • Scores can be positive, zero, or negative.
  • The score part should be converted to an integer before processing.
  • The average is the arithmetic mean of all scores for that student.
  • Compare students using the exact average value. Do not use floor, ceil, rounding, or integer division for comparison.
  • If a student appears only once, that score itself is the average.
  • If multiple students have the same highest average, return the lexicographically smaller name.
  • Assume the input contains at least one entry.

Method Signature

String highestAverageScore(List<String> marks)
  • Each string represents one entry in the format studentName,score.
  • Return the student name whose average score is the highest.
Example:
  • "Jethiya,20"
  • "Bida,50"

Constraints

  • 1 ≤ marks.size()
  • Each entry contains exactly one student name and one score.
  • Each entry contains exactly one comma.
  • Each score string is a valid integer representation.
  • Student names are non-empty strings.
  • Student names do not contain commas.

Output

Return a String representing the student name with the maximum average score.

Examples

Example 1:

Method call: highestAverageScore(marks = List.of("Jethiya,20", "Bida,50", "Iyer Idli,99", "Jethiya,25"))

Average scores:
  • Jethiya = (20 + 25) / 2 = 22.5
  • Bida = 50
  • Iyer Idli = 99
Output: "Iyer Idli"


Example 2:

Method call: highestAverageScore(marks = List.of("Alice,-10", "Bob,-5", "Alice,0"))

Average scores:
  • Alice = (-10 + 0) / 2 = -5
  • Bob = -5
Both students have the same highest average, so return the lexicographically smaller name.

Output: "Alice"


Example 3:

Method call: highestAverageScore(marks = List.of("Ravi,30"))

Ravi appears once, so his average is 30.

Output: "Ravi"




Please use Laptop/Desktop or any other large screen to add/edit code.