Message Rate Limiter
Asked at Amazon· Screen
Reported by the problem's creator, not verified
A logging service receives timestamped messages and suppresses repeats. Message i carries the text messages[i] and arrives at time timestamps[i]. The timestamps never decrease, and messages are processed in the order given.
Examples
Example 1
Input: timestamps =
[1,3,11,12,12,15,21,21,22], messages =["disk full","disk full","disk full","disk full","cpu hot","cpu hot","disk full","disk full","cpu hot"], window_seconds =10Output:
[true,false,true,false,true,false,true,false,true]Explanation: With a window of 10: 'disk full' is accepted at 1, rejected at 3, accepted at 11 (exactly 10 after the last accepted copy) and rejected at 12. 'cpu hot' has its own timer: accepted at 12, rejected at 15. At 21 'disk full' is accepted (10 after 11) and its copy at the same time is rejected; 'cpu hot' at 22 is accepted (10 after 12).