Count Failing, Passing and Distinction Scores from Percentage Thresholds

Read the full interview experience this question came from →

Quick Overview

Given an array of student exam scores as percentages, count how many students failed with under 50, passed with 50 to 80 inclusive, or passed with distinction above 80, and return the three counts in order. It tests careful handling of inclusive and exclusive boundaries and empty input.

Count Failing, Passing and Distinction Scores from Percentage Thresholds

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Online Assessment

You are given an array of integers `scores`, where the index is a student ID and the value is that student's exam score as a percentage. Each student is graded as follows: - below 50: **failed**, - from 50 to 80 inclusive: **passed**, - above 80: **passed with distinction**. Return an array of three integers: the number of students who failed, the number who passed, and the number who passed with distinction, in that order. ### Function Signature ```python def grade_counts(scores: list[int]) -> list[int]: ``` ### Rules - A score of exactly 50 or exactly 80 counts as passed; a score of exactly 81 counts as passed with distinction. - Every student falls into exactly one of the three groups, so the three counts sum to `len(scores)`. - An empty array returns `[0, 0, 0]`. ### Constraints - `0 <= len(scores) <= 100000` - `0 <= scores[i] <= 100` ### Examples **Example 1** - Input: `scores = [30, 50, 65, 80, 81, 95, 49]` - Output: `[2, 3, 2]` - Explanation: 30 and 49 fail; 50, 65 and 80 pass; 81 and 95 pass with distinction. **Example 2** - Input: `scores = [100, 100]` - Output: `[0, 0, 2]` - Explanation: Both students scored above 80. **Example 3** - Input: `scores = []` - Output: `[0, 0, 0]` - Explanation: With no students, every count is zero.

Overview: Given an array of student exam scores as percentages, count how many students failed with under 50, passed with 50 to 80 inclusive, or passed with distinction above 80, and return the three counts in order. It tests careful handling of inclusive and exclusive boundaries and empty input.

Read the full Software Engineer interview experience this question came from

|Home/Coding & Algorithms
Sep 6, 2026
easySoftware EngineerOnline AssessmentCoding & Algorithms
0
0

You are given an array of integers scores, where the index is a student ID and the value is that student's exam score as a percentage. Each student is graded as follows:

  • below 50: failed ,
  • from 50 to 80 inclusive: passed ,
  • above 80: passed with distinction .

Return an array of three integers: the number of students who failed, the number who passed, and the number who passed with distinction, in that order.

Function Signature

def grade_counts(scores: list[int]) -> list[int]:

Rules

  • A score of exactly 50 or exactly 80 counts as passed; a score of exactly 81 counts as passed with distinction.
  • Every student falls into exactly one of the three groups, so the three counts sum to len(scores) .
  • An empty array returns [0, 0, 0] .

Constraints

  • 0 <= len(scores) <= 100000
  • 0 <= scores[i] <= 100

Examples

Example 1

  • Input: scores = [30, 50, 65, 80, 81, 95, 49]
  • Output: [2, 3, 2]
  • Explanation: 30 and 49 fail; 50, 65 and 80 pass; 81 and 95 pass with distinction.

Example 2

  • Input: scores = [100, 100]
  • Output: [0, 0, 2]
  • Explanation: Both students scored above 80.

Example 3

  • Input: scores = []
  • Output: [0, 0, 0]
  • Explanation: With no students, every count is zero.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...