Quick Overview

A coding task that classifies a list of exam scores, given as percentages, into failed, passed without honors and passed with honors bands, and returns the three counts in a fixed order. It tests careful handling of the inclusive and exclusive boundaries at 50 and 80 percent.

Count Failed, Passed and Honors Exam Results From Percentage Scores

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Online Assessment

Students take an exam, and each result is a percentage score. Classify every result into one of three bands and count how many results fall into each band. ### Function Signature ```python def count_result_bands(results: list[int]) -> list[int]: ``` ### Rules - A result below 50 is **Failed**: `score < 50`. - A result from 50 to 80, both inclusive, is **Passed without Honors**: `50 <= score <= 80`. - A result above 80 is **Passed with Honors**: `score > 80`. - Return a list of exactly three integers in this order: `[failed, passed_without_honors, passed_with_honors]`. - Every result is counted in exactly one band, so the three counts sum to `len(results)`. ### Constraints - `1 <= len(results) <= 100` - Each `results[K]` is an integer with `0 <= results[K] <= 100`. The report states the band limits as percentages without giving the score range; this version fixes it to whole percentages from 0 to 100. ### Examples **Example 1** ```text Input: results = [50, 80, 81, 99, 30, 77, 67] Output: [1, 4, 2] ``` 30 is the only failed result. 50 and 80 sit exactly on the band limits and, together with 77 and 67, pass without honors. 81 and 99 pass with honors. **Example 2** ```text Input: results = [30, 30, 49] Output: [3, 0, 0] ``` **Example 3** ```text Input: results = [0, 100] Output: [1, 0, 1] ```

Overview: A coding task that classifies a list of exam scores, given as percentages, into failed, passed without honors and passed with honors bands, and returns the three counts in a fixed order. It tests careful handling of the inclusive and exclusive boundaries at 50 and 80 percent.

Read the full Google Software Engineer interview experience this question came from

Students take an exam, and each result is a whole percentage score. Classify every result into exactly one of three bands and count how many results fall into each band. Implement `count_result_bands(results)`. ### Bands - **Failed**: the score is below 50 (`score < 50`). - **Passed without Honors**: the score is from 50 to 80, both inclusive (`50 <= score <= 80`). - **Passed with Honors**: the score is above 80 (`score > 80`). ### Output Return a list of exactly three integers in this order: `[failed, passed_without_honors, passed_with_honors]`. Every result is counted in exactly one band, so the three counts always sum to `len(results)`. A band that receives no results has count 0. ### Constraints - `1 <= len(results) <= 100` - Each `results[K]` is an integer with `0 <= results[K] <= 100` (a whole percentage). - Every returned count is between 0 and 100, so no value comes near 2^31 - 1; plain 32-bit integers suffice in every language. ### Example 1 ```text Input: results = [50, 80, 81, 99, 30, 77, 67] Output: [1, 4, 2] ``` 30 is the only failed result. 50 and 80 sit exactly on the band limits and, together with 77 and 67, pass without honors. 81 and 99 pass with honors. ### Example 2 ```text Input: results = [30, 30, 49] Output: [3, 0, 0] ``` Every result is below 50, so all three fail and the other two counts are 0.

Constraints

  • 1 <= len(results) <= 100
  • Each results[K] is an integer with 0 <= results[K] <= 100 (a whole percentage)
  • The result is exactly three counts [failed, passed_without_honors, passed_with_honors], each between 0 and 100 and summing to len(results); every value fits in a 32-bit integer

Examples

Input: ([50, 80, 81, 99, 30, 77, 67],)

Expected Output: [1, 4, 2]

Explanation: Source example 1: 30 fails; 50, 80, 77 and 67 pass without honors (50 and 80 sit on the inclusive limits); 81 and 99 earn honors.

Input: ([30, 30, 49],)

Expected Output: [3, 0, 0]

Explanation: Source example 2: every result is below 50, including the repeated 30 and the boundary 49, so the other two bands are 0.

Hints

  1. Decide carefully which band each limit value belongs to: both 50 and 80 are inclusive limits of the middle band.
  2. Every result lands in exactly one band, so the three counts must add up to the number of results.
  3. The output order is fixed: failed first, then passed without honors, then passed with honors.

Loading coding console...

Show the approach

Approach

Algorithm: scan the results once while keeping three counters. For each score, first test score < 50 (Failed); otherwise test score <= 80 (Passed without Honors, which covers exactly 50 through 80 because the first test already excluded everything below 50); otherwise the score is above 80 (Passed with Honors). Return the counters as [failed, passed_without_honors, passed_with_honors].

Invariant: after processing the first i results, the three counters hold the band counts of exactly that prefix and sum to i.

Correctness: the three band conditions (score < 50, 50 <= score <= 80, score > 80) are pairwise disjoint and together cover every integer, so each score increments exactly one counter, namely the counter of its band. When the scan ends the counters equal the band counts of the whole list and sum to len(results).

Edge cases: both limit values 50 and 80 belong to the middle band, while 49 fails and 81 earns honors; the domain extremes 0 and 100 fall in the outer bands; a single result yields one 1 and two 0s; a band that receives no results reports 0; the output order is always failed, then without honors, then with honors.

Time complexity:
O(n)
Space complexity:
O(1)