Loading...
Loading...
Loading...
A class has n marks. For each of q scores, print how many students have a mark at or below that score. Scanning all marks for every score is too slow.
Example
Input
5 3 72 95 88 60 95 60 90 100
Output
1 3 5
Try the problem first. Open one hint at a time.
Counting with a loop is O(n) per score, so O(n × q) in total.
Sort the marks once. bisect_right(marks, score) is exactly how many marks are at or below the score.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor