Stopping comment spam

Write code · Challenge · §5.2 Queues

times holds, in order, the times (in seconds) at which a user wrote comments. To stop spam, a comment written at second t is blocked instead of being posted if k or more comments have already been posted from second t - 59 to second t (both included). Comments with the same time are written one at a time, in the order they appear in times. Blocked comments do not count as posted comments.

For example, a comment posted at second 0 counts toward the limit for comments written up to second 59, but not for comments written at second 60 or later. Complete the function solution, which returns the number of blocked comments.

Function

solution(times, k)

Constraints

Examples

timeskresult
[1, 2, 3, 4, 5]32
[0, 30, 50, 100]21

Starter code

def solution(times, k):
    answer = 0
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.