Logger Rate Limiter with Every-Arrival History
Problem statement
Messages arrive in nondecreasing integer timestamp order. For each pair [timestamp,message], print the message exactly when it has not arrived during the previous 10 seconds: if its prior arrival time is last, require timestamp-last >= 10.
Whether printed or suppressed, every arrival becomes the new last time for that message. Different messages are tracked independently.
Return one boolean per arrival, true when printed.
Function
shouldPrintMessages(timestamps: int[], messages: String[]) → boolean[]Examples
Example 1
timestamps = [0,5,12]messages = ["x","x","x"]return = [true,false,false]The arrival at 5 is suppressed but resets history, so 12 is only seven seconds later and is also suppressed.
Example 2
timestamps = [1,2,11,12]messages = ["a","b","a","b"]return = [true,true,true,true]Each message's arrivals are exactly ten seconds apart.
Example 3
timestamps = []messages = []return = []No arrivals produce no decisions.
Constraints
0 <= timestamps.length = messages.length <= 200000.- Timestamps are nondecreasing integers in
[0,10^9]. - Messages are nonempty case-sensitive strings.