Passing Score Count with count()
A teacher has a list of quiz scores and wants to know how many students reached the passing mark. A passing score is any value greater than or equal to 75.
Your task is to return how many scores meet that rule. The result should be a number, not a list.
For example, if the input is [60, 75, 80, 70, 90], the answer should be 3 because 75, 80, and 90 all count as passing. If the input is [50, 55, 60], the answer should be 0.
This challenge focuses on the count() terminal operation in a Java stream. The stream should filter the passing scores first, then count how many remain.
Example Input & Output
Three scores meet the passing rule.
No score reaches 75 or above.
Scores equal to 75 still count as passing.
Algorithm Flow

Solution Approach
This problem naturally splits into two Stream API steps. First, keep only the scores that satisfy the passing rule. Second, count how many values passed that filter.
The passing rule is simple: a score counts if it is at least 75. That means the filtering step can be written as score -> score >= 75. Once that is in place, Java's count() method gives the size of the filtered stream as a long.
A direct stream pipeline looks like this:
This reads clearly because each stage mirrors the problem statement. The filter() stage decides who passes, and the count() stage answers how many such scores exist.
The runtime is O(n) for n scores since each value is checked once, and the extra space is minimal because no new collection is built.
Best Answers
import java.util.List;
class Solution {
public static long countPassingScores(List<Integer> scores) {
return scores.stream()
.filter(score -> score >= 75)
.count();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
