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