Grade Distribution
Medium · rating 1100 · arrays
The first line contains n. The second line contains n scores (0–100). Print five space-separated counts: the number of A (90–100), B (80–89), C (70–79), D (60–69) and F (below 60) grades, in that order.
Editorial
Grade Distribution buckets scores into letter grades A–F and reports the counts. Map each score to a bucket with a short chain of threshold comparisons and tally.
b = [0]*5 # A B C D F
for s in scores:
if s >= 90: b[0] += 1
elif s >= 80: b[1] += 1
elif s >= 70: b[2] += 1
elif s >= 60: b[3] += 1
else: b[4] += 1
print(*b)Complexity
Time: O(n). Space: O(1).