← 返回 snowflake 的题目列表Rate Limiter Impact Analysis
类型:online_judge
Imagine you're running a social media website and it just went viral. You've noticed that the incoming traffic is higher than you've ever designed your servers for, so you decide to add a rate limiter to prevent your website from going out of service. Now, you want to analyze the impact of your rate limiter and see how many requests to your website get dropped. Given an array where each index corresponds to request ID and each value is the time when the request arrived, return the times of dropped requests given the following rules:
There can be a max of 3 requests per second
There can't be more than 20 requests per 10 seconds
Example test case:
Input: requests = [1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 8, 9, 10]
Output: [1, 1, 1, 2]
Explanation: Exceeds the maximum of 3 requests per second, so the earliest requests are dropped.
Example
Input
1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 8, 9, 10