← 返回 roblox 的题目列表Log Rate Limiter (Storefront Logs)
类型:online_judge
Problem: Storefront Log Rate Limiter
You are given a stream of log events. Each event contains at least:
timestamp: arrival time (assume integer seconds or milliseconds)
store_id: storefront identifier
(optional) event_type / message
Implement a rate limiter that decides whether each log should be accepted and written downstream.
Requirements
Rate limit independently per store_id.
In any sliding time window of length window, allow at most limit logs per store_id; extra logs must be rejected.
Output an ALLOW/REJECT decision for every input event.
I/O (conceptual)
Input: events (timestamp, store_id) in arrival order, plus window and limit.
Output: ALLOW or REJECT per event.
Example
window = 10s, limit = 3
(1, A) -> ALLOW
(2, A) -> ALLOW
(3, A) -> ALLOW
(4, A) -> REJECT
(12, A) -> ALLOW
Constraints
High-throughput stream processing.
Aim for amortized ~O(1) per event.
The original post did not include full details; this is a standard, interview-ready formulation (per-store sliding window rate limiting).
Example
Input
10 3
5
1 A
2 A
3 A
4 A
12 A
Output
ALLOW
ALLOW
ALLOW
REJECT
ALLOW