모든 챌린지
보통 3명 해결 정답률 75.0%

Gradebook Top Student

Find the student with the highest average score.

배우게 될 내용

  • Average each row of scores
  • Find the best student
  • Break ties consistently

문제

번역본 보기

Each row of scores holds one student's test scores. Compute each student's average with a helper function and return the row index of the student with the highest average. If several tie, return the smallest index.

Implement top_student(scores).

Input

scores: One row of scores per student; every row has at least one score.

Output

Return the index of the top student.

제약 조건

1 ≤ students ≤ 1,000; 1 ≤ scores per student ≤ 100; 0 ≤ score ≤ 100

예시

예시 1
입력:
scores = [
    [80, 90],
    [95, 85],
    [70, 100]
]

예상 출력:
expected = 1
입력:
std::vector<std::vector<long long>> scores = {
    {80, 90},
    {95, 85},
    {70, 100}
};

예상 출력:
long long expected = 1;
입력:
long[][] scores = new long[][] {
    new long[] {80, 90},
    new long[] {95, 85},
    new long[] {70, 100}
};

예상 출력:
long expected = 1;

설명

Averages are 85, 90 and 85, so student 1 has the highest average.

예시 2
입력:
scores = [
    [60],
    [60, 60]
]

예상 출력:
expected = 0
입력:
std::vector<std::vector<long long>> scores = {
    {60},
    {60, 60}
};

예상 출력:
long long expected = 0;
입력:
long[][] scores = new long[][] {
    new long[] {60},
    new long[] {60, 60}
};

예상 출력:
long expected = 0;

설명

Both averages are 60; the tie goes to the smaller index, 0.

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Compare students by their average score, not by a single test.

힌트 2

Compute each row’s average and keep the best index seen so far.

힌트 3

When averages tie, keep the earlier student instead of replacing it.

예상 복잡도

O(total scores) time, O(1) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

# 코더 언어 시간 메모리 AI 평가 풀이
1 ННикита Python 633 ms - 4/5 코드 보기
2 MSMichael Stoddart Python 692 ms - 3/5 코드 보기
3 LMLaura Mahlow Python 757 ms - 4/5 코드 보기

다른 사람의 풀이 보기

커뮤니티 풀이

스포일러: 아래에 전체 풀이 3개가 있습니다 먼저 직접 풀어보세요. 다른 개발자의 코드와 AI 리뷰도 참고할 수 있습니다. 로그인하고 문제를 풀면 토론에 참여할 수 있습니다.